Next.js Discord

Discord Forum

How to cache in Next JS

Answered
Eyebrowed Thrush posted this in #help-forum
Open in Discord
Avatar
Eyebrowed ThrushOP
What is best way to cache in the next js to reduce the db queries
One is normal that we perform on the next js api request in the server pages


I am looking for something beyond those pages things based on user caching
example
for examples some requested whom had liked the blog a now i will load that thing from database and send it to user. then next user request that thing again i need ot re run that query again.
Can i cache this kind of thing if yes how i should like using redis or what


any blog or video could be helpful
Answered by B33fb0n3
you might want to take a look into the docs for caching. There is a whole page about it with best pratices and more: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching

To answer your question shortly: you can use the data cache. This can be used either with fetch or with unstable_cache to cache data.
View full answer

2 Replies

Avatar
you might want to take a look into the docs for caching. There is a whole page about it with best pratices and more: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching

To answer your question shortly: you can use the data cache. This can be used either with fetch or with unstable_cache to cache data.
Answer
Avatar