Api endpoint is still returning the cached response (network tab size - "(disk cache)") - the response was cached on the client browser
Describe the bug
When creating api endpoint with defineCachedEventHandler or cachedEventHandler even after clearing the cache in nitro it still returns cached responses due to client browser caching the functions.
Using:
shouldBypassCache,
shouldInvalidateCache
runs them only when the response isn't cached in the browser making it impossible to bypass or invalidate it in the endpoint itself without clearing browser cache beforehand.
Additional context
Current workarounds I've found:
Adding belows code to the definedefineCachedEventHandler ensures that clients browser won't cache the function which ensures we now have full control over the cache and can invalidate it manually. We can even use the shouldBypassCache or shouldInvalidateCache. and bypass the cache on will which wasn't previously possible due to browser cache.
Creating a defineCachedFunction and then using it in defineEventHandler makes it possible to clear cache manually. This approach ensures that the client browser doesn't cache the response so we don't need to create unique headers for each request.
Note:
If this is intended behaviour please do let me know. It seems odd that it isn't mentioned in the nitro documentation (or I just haven't look for it good enough). Regardless if it is in the docs I think it might be good to mention it here: nitro cache docs.
Environment
Reproduction
create api endpoint with defineCachedEventHandler
set basic parameters like maxAge, name, getKey (optional for debugging)
remove the cache files manually or by running:
observe that files get removed from disk
Api endpoint is still returning the cached response (network tab size - "(disk cache)") - the response was cached on the client browser
Describe the bug
When creating api endpoint with defineCachedEventHandler or cachedEventHandler even after clearing the cache in nitro it still returns cached responses due to client browser caching the functions. Using:
runs them only when the response isn't cached in the browser making it impossible to bypass or invalidate it in the endpoint itself without clearing browser cache beforehand.
Additional context
Current workarounds I've found:
Adding belows code to the definedefineCachedEventHandler ensures that clients browser won't cache the function which ensures we now have full control over the cache and can invalidate it manually. We can even use the
shouldBypassCache
orshouldInvalidateCache.
and bypass the cache on will which wasn't previously possible due to browser cache.Second workaround:
Creating a
defineCachedFunction
and then using it indefineEventHandler
makes it possible to clear cache manually. This approach ensures that the client browser doesn't cache the response so we don't need to create unique headers for each request.Note: If this is intended behaviour please do let me know. It seems odd that it isn't mentioned in the nitro documentation (or I just haven't look for it good enough). Regardless if it is in the docs I think it might be good to mention it here: nitro cache docs.
Logs
No response