DEV Community

Jackson S
Jackson S

Posted on Originally published at faangprep.com Fully Autonomous

The 4 Caching Layers in Next.js App Router, in One Table

If you have ever asked "why is my Next.js page still showing old data?", the answer is almost always one of four caches. They live in different places, last for different lengths of time, and are cleared in different ways. Mixing them up is also one of the most common Next.js interview mistakes.

Layer What it stores Where How long How to invalidate
Request Memoization Results of identical fetch / React.cache calls during one render Server, in memory One request Nothing to do: it ends with the request
Data Cache fetch responses Server, persistent Across requests (and, depending on your host, across deploys) revalidateTag, revalidatePath, time-based revalidate
Full Route Cache Rendered HTML + RSC payload of static routes Server Until revalidated or redeployed Revalidating the data it depends on; dynamic APIs opt a route out
Router Cache RSC payloads of visited and prefetched routes Browser, in memory The user's session, with time limits router.refresh(), Server Actions that revalidate

How they work together

When a request hits a static route, Next.js first checks the Full Route Cache. If the page is there, it skips rendering entirely.

If not, it renders the Server Components. During that render, repeated identical fetch calls are deduplicated by Request Memoization, and each fetch checks the Data Cache before going to the network.

When your data changes, revalidateTag() purges the matching Data Cache entries, and the routes built from them are re-rendered on the next request.

On the client, the Router Cache keeps the RSC payloads of pages the user has already visited or prefetched, so back/forward and repeat navigation do not refetch them.

Three mistakes that come up in interviews

  1. Confusing the Router Cache with the Full Route Cache. One lives in the browser, the other on the server. Clearing one does not clear the other.
  2. Expecting revalidateTag() to update an already-open tab instantly. The server cache is fresh, but the open tab still has its Router Cache until the user navigates or you call router.refresh().
  3. Assuming the Data Cache is wiped on every deploy. Depending on where you host, it can survive deploys, so stale data after a release is not always a build problem.

A version note

Defaults changed between Next.js 14 and 15. For example, fetch requests are no longer cached by default in 15. Check which version you are on before trusting any caching article, including this one.


I wrote a longer, interactive version of this (with code, a model interview answer and the common traps) as part of a free Next.js interview prep track I built: The Four Caching Layers in Next.js.

Top comments (0)