Tag revalidation
What you need to know
Tag revalidation lets a change in public data affect all cached readers that depend on the same tag. Choose between allowing old data briefly and requiring a fresh result after a mutation.
By the end, you can: compare stale-while-revalidate and immediate expiry; choose action context.
Mark public catalog data stale after a trusted event
import { revalidateTag } from 'next/cache';export function onVerifiedPublication(event: { kind: 'catalog-published' }) { if (event.kind === 'catalog-published') revalidateTag('catalog', 'max');}Expected behavior: Partial server-side helper for use from a verified Server Function or Route Handler. A subsequent relevant access can trigger refresh; no immediate origin read is promised.
How it works
In the documented Next.js 16 model, revalidateTag with the max profile marks relevant cached entries for refresh on a subsequent visit; it is appropriate when a short stale interval is acceptable. updateTag expires tagged entries and is limited to Server Actions; it supports immediate visibility of a user's own completed write. revalidateTag is also usable in Route Handlers, where a trusted webhook may notify the application of a published revision. Do not use the historical single-argument form as a default. Invalidation is not an authorization check and not a database write. A real webhook must authenticate its sender, validate size and schema, apply replay/rate controls as appropriate and select from a finite internal set of tags. Do not accept an arbitrary tag or secret in a URL. The example is a partial server-side policy boundary, not a deployable webhook.
Require fresh data from a Server Action
import { updateTag } from 'next/cache';// Partial helper: call only within an authorized Server Action after commit.function afterAuthorizedCatalogWrite() { updateTag('catalog');}Expected behavior: Illustrative post-commit step only, not a safe standalone action. The next tagged read should not serve the expired value.
Common mistake
Calling updateTag from a Route Handler is not supported. Do not expose an unauthenticated invalidation action; the helper above demonstrates the API position only. The stale strategy is not a guarantee of immediately visible new data.
Practice and verification
Compare an editorial publication notice (brief stale content allowed) with an editor saving a title (read-your-own-writes). Choose API, context and expected sequence. Include a denied invalidation attempt and confirm it makes no cache change.
Scope: App Router, proposed Next.js 16.x and React 19, Cache Components enabled in a separate fixture. Framework snippets are staged and not executed; local pure models are not framework evidence. Exact patched dependencies and platform contracts are pending.
Further reading: Revalidate Tag · Update Tag · Revalidating