Next.js Discord

Discord Forum

is unstable_cache server-side?

Answered
neon posted this in #help-forum
Open in Discord
I have a question about the unstable_cache function in Next.js:

The cached data is stored on the server right? So does that mean that the data will be revalidated on the server side even when the website isn't visited? For example, if I set revalidate to 10 minutes and deploy my app, will the cache get revalidated every 10 minutes of the deployment even when no requests are made i.e. the website isn't visited by anyone?
Answered by joulev
yes, but no. revalidate in unstable_cache works the same as the revalidate export, i.e. a revalidation process is initiated in the background when the first request arrives after the 10 minutes duration has elapsed
View full answer

5 Replies

Answer
That also means if the cache is stale when a request comes in, the user will get served the stale content and trigger a revalidation too, therefore there won't be a delay for data fetching in either case (whether the cache is stale or not)
@neon That also means if the cache is stale when a request comes in, the user will get served the stale content and trigger a revalidation too, therefore there won't be a delay for data fetching in either case (whether the cache is stale or not)
yes, and yes.

you can set unstable_cache so that it always serves fresh data after the 10 minutes, however. so instead of initiating the revalidation in the background, you can make it so that the request needs to wait until after the revalidation has completed. of course this means that request is slower than a request that hits the cache