Skip to the solution
HardSystem Design5 min read

What are the caching layers in Next.js (Request Memoization, Data Cache, Full Route Cache, Router Cache)?

444 views

The problem

Question presented to candidate: "Next.js has several caches that interact. Name them, tell me where each lives and how long it lasts, and how you invalidate each one."

What a strong answer should cover:

  • Request Memoization: identical fetch GETs within one server render run once; lives for one request.
  • Data Cache: fetch results opted in with force-cache or revalidate, persisted across requests and deployments until revalidated.
  • Full Route Cache: the HTML and RSC payload of static routes, produced at build time or revalidation.
  • Router Cache (now called the Client Cache): RSC payloads kept in the browser memory for back and forward navigation and prefetched routes.
  • Invalidation: revalidatePath, revalidateTag, time-based revalidate, and router.refresh() for the client side; Next.js 16 docs label this four-cache model the "previous model", superseded by Cache Components.

Clarifying questions expected:

  • "Is Cache Components enabled?" β€” with it, caching is opt-in with 'use cache' and the old layer names mostly disappear.
  • "Where is the stale data showing up: first load or client navigation?" β€” it points to a different layer.

Code / implementation expected: Optional β€” a fetch that touches each layer, and the calls that clear them.

  • nextjs
  • caching
  • data-cache
  • router-cache

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

5 min read Β· 8 sections

Read the code

One fetch touching each layer, and what clears it
// app/products/page.tsx  (static route -> Full Route Cache)
export default async function Products() {
  // Data Cache: persisted until the tag is revalidated
  const res = await fetch("https://api.example.com/products", {
    cache: "force-cache",
    next: { tags: ["products"] },
  });
  const products = await res.json();
  return <ul>{products.map((p: { id: string; name: string }) => <li key={p.id}>{p.name}</li>)}</ul>;
}

// app/products/actions.ts
"use server";
import { revalidateTag, revalidatePath } from "next/cache";

export async function productChanged() {
  revalidateTag("products", "max");   // Data Cache entries tagged "products"
  revalidatePath("/products");        // the prerendered route and client payloads
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 116 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextHard

How do you implement dynamic Open Graph images in Next.js (ImageResponse)?

Continue