This page covers revalidation with Cache Components (
cacheComponents: true). For the previous model, see the Caching and Revalidating (Previous Model) guide.- Time-based revalidation: Automatically refresh cached data after a set duration using
cacheLife - On-demand revalidation: Manually invalidate cached data after a mutation using
revalidateTag,updateTag, orrevalidatePath
Time-based revalidation with cacheLife
cacheLife controls how long cached data remains valid. Use it inside a use cache scope:
cacheLife accepts a profile name or a custom object with stale, revalidate, and expire fields:
A cache is considered “short-lived” when it uses the
seconds profile, revalidate: 0, or expire under 5 minutes. Short-lived caches are automatically excluded from prerenders.On-demand revalidation
cacheTag
Tag cached data so it can be invalidated on-demand:
revalidateTag
revalidateTag invalidates cache entries by tag using stale-while-revalidate semantics — stale content is served immediately while fresh content loads in the background. Ideal when a slight delay in updates is acceptable:
revalidateTag in a Server Action or Route Handler. The second argument sets how long stale content can be served while fresh content generates in the background. Using 'max' gives the longest stale window.
updateTag
updateTag immediately expires cached data for read-your-own-writes scenarios — the user sees their change right away instead of stale content. Can only be used in Server Actions:
revalidatePath
revalidatePath invalidates all cached data for a specific route path:
Comparing the APIs
updateTag | revalidateTag | revalidatePath | |
|---|---|---|---|
| Where | Server Actions only | Server Actions and Route Handlers | Server Actions and Route Handlers |
| Behavior | Immediately expires cache | Stale-while-revalidate | Invalidates route path |
| Use case | Read-your-own-writes | Background refresh | Route-wide invalidation |
What to cache
Cache data that:- Doesn’t depend on runtime data (cookies, headers, search params)
- You’re OK serving from cache for a period of time
revalidateTag to refresh content when it actually changes, rather than expiring the cache preemptively.
