Closed AbhishekPrajapati closed 3 years ago
Hey @AbhishekPrajapati
Thanks for using axios-cache-adapter.
By default requests with query parameters are excluded from cache. You need to set the exclude.query
option to false
.
const cache = setupCache({
maxAge: 15 * 60 * 1000,
store: storageInfo,
key: req => req.url.replace(window.APP_CONFIG.API_URL, ''),
exclude: {
query: false, // allow to cache requests with query parameters
filter: (req, a) => {
if (req.method.toLowerCase() === 'get' && cachedAPIs && cachedAPIs.indexOf(req.url.toLowerCase()) != -1) {
return false;
}
return true;
}
},
clearOnStale: true,
});
Be advised, the query parameters are serialized and used in the cache key so requests to the same URL with different query parameters are cached separately 🙂
I'll let you close the issue if all is good.
Cheers
Check out the full list of options: https://github.com/RasCarlito/axios-cache-adapter#setupcacheoptions
Yeap @RasCarlito, That is working properly by setting exclude.query
option to false
.
I appreciate your quick response.
It caches GET requests but when any GET request has query string, It is not caching.
Example URL is like: 'api/candidates?active=true'