Revalidating
Learn how to revalidate cached data using time-based and on-demand strategies.
This page covers revalidation with Cache Components, enabled by setting cacheComponents: true in your next.config.ts file. If you're not using Cache Components, see the Caching and Revalidating (Previous Model) guide.
Revalidation is the process of updating cached data. It lets you keep serving fast, cached responses while ensuring content stays fresh. There are two strategies:
- 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.
cacheLife
cacheLife controls how long cached data remains valid. Use it inside a use cache scope to set the cache lifetime.
cacheLife accepts a profile name or a custom configuration object:
| Profile | stale | revalidate | expire |
|---|---|---|---|
seconds | 0 | 1s | 60s |
minutes | 5m | 1m | 1h |
hours | 5m | 1h | 1d |
days | 5m | 1d | 1w |
weeks | 5m | 1w | 30d |
max | 5m | 30d | ~indefinite |
For fine-grained control, pass an object:
Good to know: 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 and become dynamic holes instead. See Prerendering behavior for details.
See the cacheLife API reference for all profiles and custom configuration options.
cacheTag
cacheTag lets you tag cached data so it can be invalidated on-demand. Use it inside a use cache scope:
Once tagged, invalidate the cache using revalidateTag or updateTag.
See the cacheTag API reference to learn more.
revalidateTag
revalidateTag invalidates cache entries by tag using stale-while-revalidate semantics — stale content is served immediately while fresh content loads in the background. This is ideal for content where a slight delay in updates is acceptable, like blog posts or product catalogs.
You can reuse the same tag in multiple functions to revalidate them all at once. Call revalidateTag in a Server Action or Route Handler.
Good to know: The second argument sets how long stale content can be served while fresh content generates in the background. Once it expires, subsequent requests block until fresh content is ready. Using 'max' gives the longest stale window.
See the revalidateTag API reference to learn more.
updateTag
updateTag immediately expires cached data for read-your-own-writes scenarios — the user sees their change right away instead of stale content. Unlike revalidateTag, it can only be used in Server Actions.
updateTag | revalidateTag | |
|---|---|---|
| Where | Server Actions only | Server Actions and Route Handlers |
| Behavior | Immediately expires cache | Stale-while-revalidate |
| Use case | Read-your-own-writes (user sees their change) | Background refresh (slight delay OK) |
See the updateTag API reference to learn more.
revalidatePath
revalidatePath invalidates all cached data for a specific route path. Use it when you want to revalidate a route without knowing which tags are associated with it.
Good to know: Prefer tag-based revalidation (revalidateTag/updateTag) over path-based when possible — it's more precise and avoids over-invalidating.
See the revalidatePath API reference to learn more.
What should I cache?
Cache data that doesn't depend on runtime data and that you're OK serving from cache for a period of time. Use use cache with cacheLife to describe that behavior.
For content management systems with update mechanisms, use tags with longer cache durations and rely on revalidateTag to refresh content when it actually changes, rather than expiring the cache preemptively.