Skip to the solution
HardFrontend6 min read

What is the Router Cache in Next.js and what are its implications?

581 views

The problem

Question presented to candidate: "A user edits an item, clicks Back, and sees the old value. Explain what the Router Cache is, why this happens, and how you fix it."

What a strong answer should cover:

  • The Router Cache (called the Client Cache in the Next.js 16 docs) is an in-memory browser cache of RSC payloads for visited and prefetched routes.
  • Back and forward navigation reuse stored payloads without a request; that is where stale screens come from.
  • Since Next.js 15, pages of dynamic routes are not reused on normal link navigation (staleTimes.dynamic defaults to 0); static routes are kept for 5 minutes.
  • It is cleared by a full reload, router.refresh(), and by revalidatePath, revalidateTag, updateTag or setting cookies inside a Server Action.
  • Layouts and loading states are reused across navigations, which is what makes navigation feel instant.

Clarifying questions expected:

  • "Was the mutation a Server Action or an API call?" β€” only the former can revalidate the client cache in the same response.
  • "Is the stale screen on Back or on a link click?" β€” Back always reuses.

Code / implementation expected: Yes β€” a Server Action that revalidates, and a client refresh.

  • nextjs
  • router-cache
  • caching
  • navigation

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

6 min read Β· 8 sections

Read the code

Revalidating from a Server Action, and refreshing after a plain fetch
// app/items/actions.ts
"use server";
import { revalidatePath } from "next/cache";
export async function rename(id: string, name: string) {
  await db.item.update({ where: { id }, data: { name } });
  revalidatePath("/items"); // server output and browser payloads for /items are dropped
}

// components/LegacySave.tsx
"use client";
import { useRouter } from "next/navigation";
export function LegacySave({ id }: { id: string }) {
  const router = useRouter();
  async function save() {
    await fetch(`/api/items/${id}`, { method: "PATCH" });
    router.refresh(); // the Route Handler could not invalidate the client cache
  }
  return <button onClick={save}>Save</button>;
}

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 115 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

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

Continue