revalidateTag lets you invalidate cached data on-demand for a specific cache tag.
It can be called in Server Functions and Route Handlers only — not in Client Components or middleware.
Parameters
The cache tag to invalidate. Must not exceed 256 characters. Case-sensitive.
Specifies the revalidation behavior:
'max'(recommended) — Marks the tag as stale and uses stale-while-revalidate semantics. Fresh data is fetched in the background on next visit.- Custom cache life profile — Any profile defined in your
cacheLifeconfig. { expire: 0 }— Expires the tag immediately (use only when external systems require it, such as webhooks).- No second argument — Deprecated. Immediately expires the tag. Migrate to
'max'orupdateTag.
Returns
revalidateTag returns void.
Tagging data
Before callingrevalidateTag, data must be tagged:
- fetch
- use cache
Good to know
- With
profile="max", revalidation is triggered only when a page using that tag is next visited — callingrevalidateTagdoes not immediately re-render pages. - The single-argument form
revalidateTag(tag)is deprecated. Use the two-argument signature. - Use
updateTagin Server Actions for immediate cache expiration instead of{ expire: 0 }.
Relationship with revalidatePath
| Function | Scope |
|---|---|
revalidateTag | Invalidates data with specific tags across all pages |
revalidatePath | Invalidates a specific page or layout path |
Examples
In a Server Action
app/actions.ts
In a Route Handler
app/api/revalidate/route.ts
Immediate expiration (webhooks)
For external services that require immediate expiration:app/api/webhook/route.ts
