Stale-while-revalidate
revalidateTag invalidates every cache entry carrying a tag. In Next.js 16 it
takes a second argument — a cacheLife profile — that enables
stale-while-revalidate behaviour:
import { revalidateTag } from 'next/cache';
export async function updateUser(id: string) {
// Mutate data
revalidateTag('user', 'max');
}
With a profile, the stale content is served immediately while fresh content is
generated in the background, so no request waits on the revalidation. The profile
sets how long stale content may be served; once that window expires, subsequent
requests block until the fresh content is ready. 'max' gives the longest window
and is the recommended default for most cases. You can also pass another built-in
profile ('hours', 'days') or an inline object such as { expire: 3600 }.
The single-argument form, revalidateTag('user'), is deprecated in 16 — pass a
profile for stale-while-revalidate, or reach for updateTag when you need
read-your-writes. Call revalidateTag from a Server Action or a Route Handler. It
is the right choice for content that can tolerate a brief delay, like a product
catalog or a blog feed.
You are about to answer a short quiz on revalidateTag(tag, profile).