I want to customize the cache and cache post requests. How should I modify my code?
Brought to you by:
tomkozak
Originally created by: bbhxwl
I want to customize the cache and cache post requests. How should I modify my code?
StrategyHandler.js:271 Uncaught (in promise) attempt-to-cache-non-get-request: Unable to cache '/api/webApi/ServiceProviderApi_GetAll?cache=100' because it is a 'POST' request and only 'GET' requests can be cached.
workbox: {
runtimeCaching:[
{
urlPattern: ({ url }) => url.pathname.startsWith('/api/webApi') && url.searchParams.has('cache'),
handler: 'CacheFirst',
method: 'POST',
options: {
cacheName: 'api-cache',
plugins: [
{
fetchDidSucceed: async ({request, response}) => {
const cacheTimeParam = new URL(request.url).searchParams.get('cache');
const maxAge = cacheTimeParam ? parseInt(cacheTimeParam, 10) : null;
if(maxAge){
}
return response;
},
},
],
},
}
]
},
Originally posted by: westonruter
Take a look at this StackOverflow answer: https://stackoverflow.com/a/59737346/93579