Caching and Revalidation
In Next.js 16 caching is explicit. With Cache Components you mark work with "use cache", give it a lifetime with cacheLife, tag it with cacheTag, and invalidate it with updateTag, revalidateTag or revalidatePath. Know which layer you are touching: render-pass memoization, the server cache, prerendered HTML, or the client router.
Key points
- 1
Caching is opt-in. A plain
fetchis not stored in the persistent cache; identical GET fetches are only memoized for one render pass (not in Route Handlers). - 2
"use cache" needs
cacheComponents: true. Its key is the build ID, a function ID and the serialized arguments, with captured closure variables bound as arguments. - 3
Cached scopes cannot read
cookies(),headers()orsearchParams. Read them outside and pass the value in, or use "use cache: private", which only caches per request and in the browser. - 4
cacheLife:
staleis the client router window (minimum 30 s),revalidatetriggers background regeneration, andexpireis the point after which a request waits. Without a cacheLife call,defaultapplies (5 m / 15 m / never). - 5
updateTag is for read-your-own-writes and only works in Server Actions. revalidateTag(tag, profile) serves stale content while revalidating, and
{ expire: 0 }is the immediate option for webhooks. - 6
Default runtime entries live in per-instance memory. Serverless rarely reuses them, so use "use cache: remote" with a cacheHandlers backend to share them. No "use cache" entry survives a new deploy.
- 7
On multi-instance self-hosting, revalidation is local unless the cache handler syncs tags through updateTags() and refreshTags().
Common traps
revalidatePath("/blog") does not refresh other pages that share the same tagged data, and with rewrites you must pass the destination path.
unstable_cache keys do not include closure variables. Leave the user ID out of the key and every user is served the first user's data.
A short-lived cache (
seconds,revalidate: 0, orexpireunder 5 minutes) nested in a "use cache" scope with no explicit cacheLife fails the build. Always set an explicit lifetime.
Test yourself on Caching and Revalidation
Ten questions, with the answer and explanation after each one.