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
staletime travels in thex-nextjs-stale-timeheader. The client keeps the content for that long. A minimum of 30 seconds is enforced so prefetched links stay usable. - Previous model:
staleTimes.dynamicdefaults to 0 since Next.js 15 (dynamic pages refetch on each navigation, though layouts and back/forward still reuse cache), andstaleTimes.staticdefaults to 5 minutes. - Back/forward navigation always reuses cached data to restore the previous view.
Invalidation
- Calling
updateTag,revalidateTag,revalidatePathorrefresh()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
1// next.config.ts (previous model tuning)2// experimental: { staleTimes: { dynamic: 30, static: 180 } }34// 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 60s9 return fetch("https://api.example.com/feed").then((r) => r.json());10}1112// app/feed/refresh-button.tsx13"use client";14import { useRouter } from "next/navigation";15import { useTransition } from "react";1617export function RefreshButton() {18 const router = useRouter();19 const [pending, start] = useTransition();20 // Re-render on the server and merge, keeping client state21 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.