Auto no cache when using prisma postgres with better-auth
using prisma postgres with better-auth for user session and user management but getting this whenever refreshing! How to implement the caching?
│ POST https://accelerate.prisma-data.net/6.4.1/sdfsdfsdfdsf4s64df35s4d1f5s4df5346sf6ds4f4/graphql 200 in 506ms (cache skip)
│ │ Cache skipped reason: (auto no cache)
2 Replies
You selected the bot's instantaneous insights. Let me compile your answer right away!
It seems like you're encountering a situation where caching is not being applied, as indicated by the "auto no cache" message. By default, Prisma Accelerate does not apply caching unless explicitly configured. This is to prevent unexpected issues that might arise from implicit caching (source).
To implement caching with Prisma Postgres, you need to define a
cacheStrategy
for your queries. This involves specifying parameters like ttl
(Time-To-Live) and swr
(Stale-While-Revalidate) to control how long data is cached and how stale data is handled while refreshing in the background.
Here's an example of how you can define a cache strategy in your query:
By setting a ttl
and swr
, you instruct Prisma to cache the query results for a specified duration and manage stale data accordingly. This should help in reducing the load on your database and improving response times.
For more detailed information on caching strategies and how to implement them, you can refer to the Prisma caching documentation.Hi 👋
Did the bot answer help? Do you still get the (cache skip) log after adding
cacheStrategy
to your queries?