0
Challenge · 19Rendering & Caching

The four caches (mental model)

Cachingused in ~80% of apps

Almost every "why is my data stale?" bug in Next.js comes from thinking there is ONE cache. There are four — different locations, different lifetimes, different ways to clear them. Interviewers ask you to name them precisely because juniors blur them into a single fuzzy blob and then can't explain why revalidating on the server didn't fix the browser.

Core idea. Next.js layers four independent caches between your database and the user's screen: Request Memoization (per-render, in React's memory), the Data Cache (persistent, on the server, across requests), the Full Route Cache (rendered HTML/RSC on the server), and the Router Cache (RSC payload in the browser). A request passes through them outside-in; to fix staleness you must know which one is holding the old value.
Playground, this isn't a screenshot
<ViewCount />no data yet
—

Press Visit to mount the component.

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