0
Challenge · 28Mutations & Auth
revalidateTag vs updateTag vs refresh
Cachingused in ~80% of apps
Three APIs ship in Next.js 16 that all sound like 'make the data fresh again' — and almost every blog post treats them as interchangeable. They are not. Pick the wrong one and either your users save a form and still see the old value, or you call an API that throws at runtime in production. Interviewers love this exactly because the names hide the difference.
Core idea. These are three different tools for three different jobs. `updateTag(tag)` is strong, read-your-writes invalidation that runs in Server Actions ONLY (it throws anywhere else). `revalidateTag(tag, profile)` is eventual, stale-while-revalidate invalidation that works in both Server Actions and Route Handlers. `refresh()` doesn't touch the cache at all — it re-fetches the uncached/dynamic data of the current view (its client twin is `router.refresh()`).
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
<ViewCount />no data yet
—
Press Visit to mount the component.
fetch
SWR CACHE (key: /views)
(empty)
SERVER (live, drifts)
1,280
visits: 0
// SWR activity log…
First visit blocks on the network. Every visit after serves the cached (stale) value instantly, then revalidates in the background and swaps in fresh data — that is the whole name made literal.
↑ play a little first, then dig in