Skip to the page

Caching in Next.js 16 · senior

Revalidation: updateTag, revalidateTag, revalidatePath and refresh

After a mutation, updateTag(tag) (Server Actions only) expires a tag so the user immediately sees their change, revalidateTag(tag, "max") refreshes in the background for everyone else (also from Route Handlers and webhooks), revalidatePath invalidates by URL, and refresh() re-renders uncached data without touching the cache.

The notes

What you must know

  • Tag data where it is cached: cacheTag("product-42") in a "use cache" scope, or fetch(url, { next: { tags: [...] } }).
  • updateTag(tag): only in Server Actions (throws elsewhere). Expires immediately; the next read waits for fresh data: read-your-own-writes. The action response includes the re-rendered page.
  • revalidateTag(tag, profile): Server Actions and Route Handlers. With "max" (recommended) it serves stale data while refreshing in the background. The one-argument form is deprecated in 16 (it behaves like updateTag). It does not include an immediate re-render in the action response.
  • revalidatePath("/products"): coarse invalidation by path (built on a special path tag).
  • refresh() (Server Actions): re-fetches the current route's uncached data, not the cache. router.refresh() is the client-side equivalent.
  • Calling any revalidation function from a Server Action clears the whole client router cache.
  • Webhook from a CMS: a Route Handler that verifies a signature/secret, then revalidateTag(tag, "max").
  • Debug stale data layer by layer: "use cache"/fetch cache, prerendered page, client router cache, CDN or reverse proxy cache, multiple instances (tags must be coordinated through a shared cache handler refreshTags).

The red pen

Common traps: mistake → fix

  • Mistake: "Use revalidatePath('/') after every mutation"

    Fix: it throws away far more than needed.

  • Mistake: "Shorten the revalidate timer to fix stale prices"

    Fix: use tags and on-demand invalidation.

  • Mistake: "updateTag works in a Route Handler"

    Fix: Server Actions only; use revalidateTag there.

Easy to hard

Questions interviewers ask, easy to hard

  1. An admin updates a price; the DB write succeeds but the page shows the old price for an hour. Debug it, then fix it so the admin sees the change immediately.
  2. updateTag vs revalidateTag(tag, "max"): when each?
  3. What does refresh() do compared with router.refresh()?
  4. A CDN in front of the self-hosted app is still stale. Why?
  5. Which API do you call from a CMS webhook?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview