Refetch when new ttl would override cached value #625
-
Hi, thanks for your great job with this library. I'm wondering how to handle a case where I fetch data from an expensive endpoint with a 12-hour ttl, but I sometimes need to ensure the data is no more than 30-min old. My understanding is that the
Is there any way to control this with the library (i.e. compute the query key, check its cached Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @jodoox, I think I understood your requirements correct. const id = 'some-id';
const currentStorage = await axios.storage.get(id)
const isCacheOlderThan30Min = myLogic(currentStorage);
axios.get('url', { id, cache: { override: isCacheOlderThan30Min } }); This should only define However, if you do not have direct access to the request property, you could just do an Also, as far as I understood, you still wanna keep the cache for 12 hours for some requests. Because, if not, you could just override the |
Beta Was this translation helpful? Give feedback.
Hey @jodoox, I think I understood your requirements correct.
override
seems to be a pretty good case of this usage. Override does not ignores cache completely,cache: false
does. You could do the following:This should only define
override: true
when the current cache is older than 30min, in which case, as the override spec says, would ignore current cache and proceed to request in the network, however it does not deletes or ignore cache/fallbacks mechanisms, which is something you should care …