Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to customize the cache and cache post requests. How should I modify my code? #3390

Open
bbhxwl opened this issue Jan 27, 2025 · 1 comment
Labels
Discuss An open question, where input from the community would be appreciated.

Comments

@bbhxwl
Copy link

bbhxwl commented Jan 27, 2025

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;
                                },
                            },
                        ],
                    },
                }
            ]
        },
@westonruter
Copy link
Collaborator

Take a look at this StackOverflow answer: https://stackoverflow.com/a/59737346/93579

@westonruter westonruter added the Discuss An open question, where input from the community would be appreciated. label Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discuss An open question, where input from the community would be appreciated.
Projects
None yet
Development

No branches or pull requests

2 participants