You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️ Please be aware that the problem I'm describing can't be reproduced in the stackblitz preview feature, once it runs with ServiceWorker. The code should be downloaded and run locally: npm install then npm run dev
Context:
I'm working on a feature that uses SWR to cache the API responses for a certain period and revalidate after the TTL.
When I switch pages, I make a request to the API, and I want the cache to be bypassed when I set the preview=true query parameter.
The problem is that the browser caches the response regardless, and when the user navigates, it still serves cached data.
Is it possible to avoid the response being cached in the browser when the cache is bypassed? Using shouldBypassCache, should it still return stale-while-revalidate headers?
Could anyone help me with that, please?
The text was updated successfully, but these errors were encountered:
I'm also facing this problem, no idea how to work around it yet. It seems to me that shouldBypassCache should run every request regardless of other parameters because in it's current state it seems pointless as you cannot bypass cache using it. Same thing goes for shouldInvalidateCache() - runs only when the response wasn't cached yet which makes it unusable (at least i don't see the point of using it in this state).
I've even tried to manually invalidate the cache before the request with an endpoint setup like so:
I'm facing the same problem. The workaround in #2738 by @dencs08 just saved me. Also, It would be nice if the Nitro Cache Guide included examples using shouldBypassCache and shouldInvalidateCache
Discussed in #2714
Originally posted by kaitoqueiroz September 5, 2024
Environment:
Operating System: Linux
Node Version: v20.15.0
Nuxt Version: 3.13.0
Package Manager: [email protected]
Reproduction
https://stackblitz.com/edit/nuxt-starter-kjhdkn?file=server%2Fapi%2Ftest.get.js
npm install
thennpm run dev
Context:
I'm working on a feature that uses SWR to cache the API responses for a certain period and revalidate after the TTL.
When I switch pages, I make a request to the API, and I want the cache to be bypassed when I set the
preview=true
query parameter.The problem is that the browser caches the response regardless, and when the user navigates, it still serves cached data.
Response headers in the first request (uncached):
Code:
Is it possible to avoid the response being cached in the browser when the cache is bypassed? Using shouldBypassCache, should it still return stale-while-revalidate headers?
Could anyone help me with that, please?
The text was updated successfully, but these errors were encountered: