P
Prisma•6mo ago
Raj

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
Raj
RajOP•6mo ago
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...
Raj
RajOP•6mo ago
cc @Nurul (Prisma) (apologies for the ping, but you were the one who responded to the above GH discussion)
Nurul
Nurul•6mo ago
Hey @Raj 👋 Can you share your query with me? Assuming this kind of query:
await prisma.user.findMany({
cacheStrategy: {
ttl: 30,
swr: 60,
},
});
await prisma.user.findMany({
cacheStrategy: {
ttl: 30,
swr: 60,
},
});
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.
Raj
RajOP•6mo ago
await prisma.userProfile.findUniqueOrThrow({
where: {
userId: userID,
},
select: {
...PLATFORM_USER_FIELDS,
},
cacheStrategy: {
ttl: 30,
swr: 60,
}
});
await prisma.userProfile.findUniqueOrThrow({
where: {
userId: userID,
},
select: {
...PLATFORM_USER_FIELDS,
},
cacheStrategy: {
ttl: 30,
swr: 60,
}
});
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)
Nurul
Nurul•6mo ago
That's weird. Which database are you using? I can try to reproduce this on our end and share it with Accelerate team.
Raj
RajOP•5mo ago
Sorry, I somehow missed this @Nurul (Prisma)! Using a Postgres DB (via Supabase)
Want results from more Discord servers?
Add your server