Skip to content

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

@bbhxwl

Description

@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;
                                },
                            },
                        ],
                    },
                }
            ]
        },

Metadata

Metadata

Assignees

No one assigned

    Labels

    DiscussAn open question, where input from the community would be appreciated.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions