revalidateTag, updateTag and revalidatePath: what each one does to your cache
Hina NakahiraCo-founder & CEO at Arkor
When the data behind a cached page changes, Next.js gives you three calls to say so. They look alike, and they do different things: one lets the next visitor see the old version while a new one is made, one makes the next visitor wait for the new one, and one works by path rather than by data. Picking the wrong one is how a page ends up stale for longer than anyone expected, or slow for the one visitor who happened to arrive first.
The API semantics below describe Next.js 16. A host’s distributed caches can add propagation delay; the last section explains what to check on Arkor.
Cached data carries tags from where it is cached: cacheTag inside a 'use cache' function or
component, or next: { tags } on a fetch.
import { cacheLife, cacheTag } from 'next/cache';
export async function getPosts() {
'use cache';
cacheLife('hours');
cacheTag('posts');
const response = await fetch('https://cms.example.com/api/posts');
return response.json();
}Next.js also gives every page tags of its own, made from its path. You never write those, and they
are what revalidatePath uses.
revalidateTag(tag, 'max'): stale while it regenerates
revalidateTag marks everything that carries the tag as stale. Nothing is regenerated at that
moment. The next request for a page that uses the tag is answered with the stale version, and sets
off a regeneration behind it. Requests that arrive while it runs get the stale version too; once it
finishes, the new version is served.
The second argument says how long stale content may still be served. With 'max', the recommended
profile, that is long enough that no visitor waits for a page that has a stale version to be
regenerated. A page with nothing cached yet, never made or since dropped, is still made while its
first visitor waits. A page that nobody visits stays stale until someone does, and that is the
point: a tag on ten thousand pages does not regenerate ten thousand pages at once.
import { revalidateTag } from 'next/cache';
export async function POST(request: Request) {
const secret = process.env.REVALIDATE_SECRET;
if (!secret || request.headers.get('authorization') !== `Bearer ${secret}`) {
return new Response('Unauthorized', { status: 401 });
}
revalidateTag('posts', 'max');
return Response.json({ revalidated: 'posts' });
}Use it where a short delay is fine: a CMS that calls a webhook when an editor publishes, a product catalog, documentation.
updateTag(tag): the next visitor waits
updateTag expires the tagged data at once. The next request does not get the old version: it waits
for the new one. It is made for reading your own writes, where someone changes something and expects
to see the change on the next page, and it can only be called from a Server Action.
'use server';
import { updateTag } from 'next/cache';
import { redirect } from 'next/navigation';
export async function publishPost(id: string) {
await db.post.publish(id);
updateTag('posts');
redirect(`/posts/${id}`);
}Outside a Server Action, in a route handler a webhook calls for example, pass { expire: 0 } to
revalidateTag for the same effect. revalidateTag with one argument is deprecated, and it behaves
like { expire: 0 }: code written before Next.js 16 that calls it that way makes a visitor wait
where 'max' would not have.
revalidatePath(path): a page, not the data
revalidatePath('/blog') marks that path for revalidation. From a Route Handler, it is
revalidated on the next visit. From a Server Function, the affected UI can update immediately. Other pages that show the same data keep their cached copies, because the call names
a page, not the data's tags.
- To expire every page of a dynamic route, name the route and its type:
revalidatePath('/blog/[slug]', 'page'). Without the type, a route pattern expires nothing. 'layout'expires the layout at that path and every page under it.- Behind a rewrite, name the page the rewrite goes to, not the address in the browser: the cache knows pages by the route file that rendered them.
Side by side
| Call | Where it can be called | The next visitor to an affected page | Use it for |
|---|---|---|---|
revalidateTag(tag, 'max') | Server Actions, route handlers | Gets the stale version, and a new one is made behind it | Content where a short delay is fine |
updateTag(tag) | Server Actions | Waits for the new version | Showing someone the change they just made |
revalidateTag(tag, { expire: 0 }) | Server Actions, route handlers | Waits for the new version | A webhook that needs the old version gone |
revalidatePath(path) | Server Functions, route handlers | Revalidates the path; UI updates depend on the caller | One page, or with 'page', a whole route |
Seeing it happen on Arkor
On Arkor, every response carries an x-arkor-edge header. On a page from the cache it says
cache=fresh or cache=stale, and seq says which generation of the page was sent; see
Response headers.
The Cache Inspector keeps the whole story. Its History lists
each invalidation as stale-while-revalidate or immediate, which is the difference between
'max' and everything else in the table above, and how far it has reached. An entry's
Generations show each recorded version of a page, where it came from, and, with Compare,
what changed between two of them. On Pro, enable recording for the project and deploy again first.
Invalidations normally propagate within a few seconds, but a location can briefly serve its previous copy while checking. Time-based regeneration can take a minute or more to reach other regions; see How soon changes appear.
About the author

Co-founder & CEO at Arkor