lisaogren / axios-cache-adapter

Caching adapter for axios. Store request results in a configurable store to prevent unneeded network requests.
MIT License
725 stars 108 forks source link

Throttle calls only if url not in cache #268

Open jodoox opened 2 years ago

jodoox commented 2 years ago

Ideally I'd want to throttle my requests that are not present in the cache (but serve them immediately if they've already been fetched). I've put below an extract from https://github.com/kuitos/axios-extensions that gives an idea of what I'm looking for

const http = axios.create({
    baseURL: '/',
    headers: { 'Cache-Control': 'no-cache' },
    adapter: throttleAdapterEnhancer(cacheAdapterEnhancer(axios.defaults.adapter))
});

It seems like this cannot be done with the adapter returned by setupCache, given that it will try to find the query in the cache and then try to fetch via network (which allows to fallback on the stale data from the cache)

Is this somehow possible with axios-cache-adapter?