Accelerate SWR option not re-fetching/revalidating cache
If my understanding of the SWR strategy is correct, the cache is supposed to be revalidated after each request (even if the cache served old data).
In my user profile component, I'm fetching the user's information from the database. When an update gets made (e.g. the user's name), refreshing the page still displays the old information. I would expect this to be the case for the first couple refreshes after the update has been made (since the cache is being revalidated/refreshed in the background), but even after a full minute the query result keeps returning the old user information.
Why is the cache not being revalidated/refreshed in the background??
6 Replies
https://github.com/prisma/prisma/discussions/23787#discussioncomment-9277949
This seems to outline exactly what I'm experiencing...
GitHub
Cache strategy SWR on Prisma Accelerate doesn't seem to work · pris...
Question Hi all. I have recently started a NextJS project with Prisma Accelerate. I managed to get it to work quite easily and I'm very happy with it, the performance is really good. However, I...
cc @Nurul (Prisma) (apologies for the ping, but you were the one who responded to the above GH discussion)
Hey @Raj 👋
Can you share your query with me?
Assuming this kind of query:
If a request comes in after
ttl
has expired, let's say at 35 second, then the stale response would be returned and simultaneously a request would be made to the database and cache will get updated. As soon as the cache gets updated, a new cycle of ttl
of 30 seconds and swr
of 60 seconds kicks in.
Like JW887 on GitHub, it doesn't seem like the request to the database is being made/processed during the SWR period. Between the 30-90 second interval post-query (when the SWR period should be hit), all queries keep returning the stale data and the cache never gets updated. The only time the updated data is received is after the full 90 seconds when the cache misses and the DB is queried directly (which would trigger another 90 seconds of stale cached data)
That's weird. Which database are you using? I can try to reproduce this on our end and share it with Accelerate team.
Sorry, I somehow missed this @Nurul (Prisma)!
Using a Postgres DB (via Supabase)