Nextjs Fundamentals · Caching & Revalidation

Stale-while-revalidate

revalidateTag(tag, profile)

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).

  1. revalidateTag in Next.js 16 takes a cacheLife profile as its second argument.
  2. revalidateTag with a profile gives ___ semantics: stale content is served while fresh content loads in the background.
  3. The recommended profile for revalidateTag is 'max'.
  4. Once the stale window expires, requests block until fresh content is ready.
  5. revalidateTag can be called from a Server Action or a Route ___.
  6. In Next.js 16 the single-argument form revalidateTag('user') is deprecated.