-
Notifications
You must be signed in to change notification settings - Fork 511
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
cachedEventHandler()
needs at least 2 calls after it is invalid
#1948
Comments
Hi. I made a minimal sandbox to reproduce: https://stackblitz.com/edit/github-avewtb?file=routes%2Findex.ts It is in fact an expected behavior. By default, we enable Stable-While-Revalidate strategy. The response will be invalidated in the background that's why you immediately get the old one until this time passes. (but notice the log that handler is immediately invoked) If you wish to get response after handler resolved, you can disable SWR using Also really strange if fs/memory behavior is different than Vercel KV. It is likely that vercel has multiple nodes but i need to investigate more. Have you checked vercel function logs if there is any specific error? |
Thanks for the super fast response! Shouldnt swr be disabled by default to prevent unexpected results and confusion? When the cache is invalid, I expect my handler function to run and return the new result immediately. Otherwise the cache seems broken to me. E.g. thinking about a button on a website that says "update" wouldnt return an updated result, isntead it would return the same cached data as before unless it is pressed a second time. Within the docs in all examples I made a minimal reproduction repo: Deployed to Vercel using Vercel KV: Indeed within development (using FS driver) it reruns the function immediately. Maybe because on dev everything is so fast? This would mean that on dev it is "wrong" while on Vercel it is correct. |
PR welcome to clarify the docs 👍🏼 Benefits of SWR behavior for non-blocking responses was important enough that we initially decided on this default. We can discuss later to change it for next major versions of nitro if enough merits. Yep maybe dev experience is fast enough so you haven't notice issue :p With disabled Unrelated: Since saw |
I would highly suggest Updated the docs to make this more clear: #1949 |
Lets move default discussion to #1950 Thanks for docs PR. Do we need to keep this issue still open? |
Environment
Nuxt: 3.8.2
H3: 1.9.0
nitropack: 2.8.0
Server: Vercel
Storage: Vercel KV (Redis)
Reproduction
server/api/tester.ts
nuxt.config.ts
Describe the bug
Using
cachedEventHandler()
with Vercel KV (Redis) requires at least 2 calls after the cache is invalid until the function runs again:maxAge
is expiredAdditional context
In development Nitro is using the FS driver and I there it seems to work as it should.
Logs
No response
The text was updated successfully, but these errors were encountered: