What is the router cache in the App Router?

The Router Cache (now called the Client Cache) is the in-memory browser cache of RSC payloads for route segments you visited or prefetched. It makes back and forward navigation instant and lets layouts be reused. How long entries stay fresh is set by cacheLife's stale value (with a 30-second minimum) or by staleTimes.

What it stores

  • Prefetched segments (App Shells or full payloads, depending on prefetch).
  • Segments rendered during navigation.
  • Shared layouts, deduplicated across routes since Next.js 16.

Freshness

  • Cache Components: each cached function's stale time travels in the x-nextjs-stale-time header. The client keeps the content for that long. A minimum of 30 seconds is enforced so prefetched links stay usable.
  • Previous model: staleTimes.dynamic defaults to 0 since Next.js 15 (dynamic pages refetch on each navigation, though layouts and back/forward still reuse cache), and staleTimes.static defaults to 5 minutes.
  • Back/forward navigation always reuses cached data to restore the previous view.

Invalidation

  • Calling updateTag, revalidateTag, revalidatePath or refresh() in a Server Function clears the whole client cache in that response.
  • router.refresh() re-requests the current route from the server and merges it, keeping client state.
  • Setting or deleting cookies in a Server Function also invalidates it.
  • A full page reload clears it entirely.

Related: Activity

With Cache Components, pages you navigate away from are kept mounted but hidden with React's <Activity>, so their state and DOM survive. That is separate from the data cache but makes Back feel instant.

Pitfall

After a mutation done outside a Server Function (for example a direct API call), the UI may show stale data until you call router.refresh().

Code example

tsx
1// next.config.ts (previous model tuning)
2// experimental: { staleTimes: { dynamic: 30, static: 180 } }
3
4// lib/data.ts (Cache Components: stale time per function)
5import { cacheLife } from "next/cache";
6export async function getFeed() {
7 "use cache";
8 cacheLife({ stale: 60, revalidate: 300, expire: 3600 }); // browser reuses it for 60s
9 return fetch("https://api.example.com/feed").then((r) => r.json());
10}
11
12// app/feed/refresh-button.tsx
13"use client";
14import { useRouter } from "next/navigation";
15import { useTransition } from "react";
16
17export function RefreshButton() {
18 const router = useRouter();
19 const [pending, start] = useTransition();
20 // Re-render on the server and merge, keeping client state
21 return <button disabled={pending} onClick={() => start(() => router.refresh())}>Refresh</button>;
22}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app