question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache based on params

See original GitHub issue

In 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:closed
  • Created 5 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
klis87commented, Mar 6, 2019

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 in action.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.

1reaction
klis87commented, Mar 3, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found