Back to results for “Caching”
Next.js › Caching

How do you control how long a fetched piece of data stays cached before it is considered stale?

Intermediate

Answer

You pass a revalidate option to the fetch call, specifying the number of seconds after which Next.js should fetch fresh data again instead of using the cached version, giving you fine grained control over how up to date each piece of data needs to be.
const res = await fetch('https://api.example.com/posts', {
  next: { revalidate: 60 }
});
Real-world example A blog revalidates its list of posts every sixty seconds, so new articles appear reasonably quickly without needing to rebuild the entire site or fetch fresh data on every single request.

Common follow-ups: What happens to users viewing the page while the data is being revalidated in the background?;Can you set different revalidate times for different fetch calls on the same page?