Cache based on params
See original GitHub issueIn my use case I am fetching many resources based on some parameter, mapId
. I’d like to cache the responses of the actions based on the url rather than the action type.
For example, I have an action getFeatures
that fetches a url with a 2 hour cache. Despite the url changing based on a passed in parameter which will alter the response the existing CacheMiddleware
will not respect this as a different request.
const getFeatures = createAction(`get features`, ({ mapId }) => {
return {
request: {
url: `/v2/maps/features/?map=${mapId}`
},
meta: {
cache: 7200, // 2 hours
}
};
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Caching content based on query string parameters
Describes how CloudFront forwards, caches, and logs query string parameters to your origin.
Read more >13.2. Caching Pages Based on Query String Parameter Values
It is fairly common practice to pass information in the query string that is used to define what is displayed on a page....
Read more >Query parameters and cached responses - Cloudflare Docs
APO serves cached content as long as the query parameters in the URL are one of the following: ref; utm_source; utm_medium; utm_campaign ...
Read more >Cache Versions of a Page Using Parameters - Microsoft Learn
You can cache multiple versions of page responses based on the parameters sent as query string values or form post values. Note. ASP.NET...
Read more >HTTP Cache-Control and params order - Stack Overflow
Thus, all cache related headers: Cache-Control , Expires , ETag etc. are all based on one precondition: resource of the same URL.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Nice. However, I think that this library should have 1st caching support anyway, because with service worker you need to manage it yourself plus you need to sync urls between service workers and redux actions.
I really want caching multiple resources built in in this libary, with ability to set
cacheSize
inaction.meta
so users could control its size.I am not sure when I will have time to do it though, hopefully sooner than later. I will let you know once done. Good you have alternative as well, so you won’t be blocked.
Actually I figured it out, we just need extra action.meta.cacheHit flag, which will be appended by middleware, thats enough to communicate with sendRequest. We could use it also in requestsReducer not to increment pending counter on request with cache hit.