Next.js Discord

Discord Forum

Caching database queries

Answered
Great-tailed Grackle posted this in #help-forum
Open in Discord
Great-tailed GrackleOP
What's the best way to cache database queries when using a db provider like drizzle/prisma? Since 'use-cache' is still experimental, I'm looking to find a stable way to do that right now aside from unstable_cache API (if there are any).
Answered by joulev
if you want to cache only a query and not, say, a whole page

then you only have "use cache" and unstable_cache.

"use cache" is experimental. unstable_cache despite the name is very stable.
View full answer

6 Replies

@Great-tailed Grackle What's the best way to cache database queries when using a db provider like drizzle/prisma? Since 'use-cache' is still experimental, I'm looking to find a stable way to do that right now aside from unstable_cache API (if there are any).
if you want to cache only a query and not, say, a whole page

then you only have "use cache" and unstable_cache.

"use cache" is experimental. unstable_cache despite the name is very stable.
Answer
Great-tailed GrackleOP
What about React.cache?
react.cache doesn't cache anything across requests. it only deduplicates the query within the lifetime of that single request
Great-tailed GrackleOP
Got it, thanks!
Chum salmon
Use TanStack 😉
+1 Tanstack Query has built in option for caching