# The Router Cache

> In-memory client caching for instant SPA navigation.

Subject: Next.js | Lesson 25 of 65 | 7 min read
Interactive lesson: https://codewithanimation.in/nextjs/router-cache
Previous: [The Full Route Cache](https://codewithanimation.in/nextjs/full-route-cache.md) | Next: [Time-based Revalidation (ISR)](https://codewithanimation.in/nextjs/time-based-revalidation.md)

## The browser's memory

The Router Cache is unique because it is the only cache in the Next.js ecosystem that lives entirely in the user's browser (client-side).

As a user navigates your application, Next.js stores the React Server Component (RSC) payload of every visited route segment directly in the browser's memory.

## Instant back/forward navigation

This cache is what gives the App Router its lightning-fast, Single Page Application (SPA) feel.

If a user visits the `/about` page, clicks a link to `/contact`, and then clicks the browser's 'Back' button, Next.js does not need to contact the server. It instantly restores the `/about` page directly from the Router Cache.

## How it invalidates

Because the Router Cache lives in the browser's memory, it is completely destroyed the moment the user hits 'Refresh' (F5) or closes the tab.

While the tab remains open, Next.js uses a `staleTime` heuristic to decide how long to keep the data. By default in Next.js 15, statically generated routes remain in the Router Cache for 5 minutes.

## Common mistake: The 'stale data' illusion

In Next.js 14, even dynamic routes were cached in the browser for 30 seconds. This led to widespread confusion: developers would submit a form, navigate back to a list, and see old data because the browser was serving it from the Router Cache.

Next.js 15 fixed this by setting the default `staleTime` for dynamic routes to 0 seconds. However, for static routes, the 5-minute cache still applies.

## Tip: router.refresh()

If you ever need to manually clear the Router Cache without forcing the user to hard-refresh the page, you can call `router.refresh()` from the `useRouter()` hook.

This tells the browser to wipe its current cache and fetch a fresh RSC payload from the server for the currently active route.

## Try it: The Browser Memory

Click around the simulated browser. Notice how navigating to a new page triggers a slow network request to the Next.js Server. However, if you navigate to a page you've already visited, it restores instantly from the Router Cache.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/router-cache

## Check yourself

### Question 1

Where is the Router Cache stored?

- A. On the Next.js origin server
- B. In a CDN edge node
- C. In the user's browser memory
- D. In the Vercel data layer

Correct answer: C

The Router Cache is the only client-side cache in Next.js. It stores RSC payloads directly in the browser's memory to enable instant navigation.

- Why not A: That is where the Data Cache lives.
- Why not B: That is where the Full Route Cache lives.
- Why not D: The Router Cache is strictly a client-side mechanism.

### Question 2

How can you programmatically force the browser to clear the Router Cache and fetch fresh data?

- A. By using the { cache: 'no-store' } fetch option
- B. By calling router.refresh()
- C. By importing the cookies() function
- D. By deleting the .next folder

Correct answer: B

Calling `router.refresh()` instructs Next.js to discard the current client-side Router Cache and request a fresh Server Component payload from the server.

- Why not A: That controls the server-side Data Cache, not the client-side Router Cache.
- Why not C: That opts out of the Full Route Cache, not the Router Cache.
- Why not D: That is a build directory, not the user's browser cache.

## Remember this

- The Router Cache lives entirely in the user's browser memory.
- It enables instant back/forward navigation.
- It is completely wiped if the user hard-refreshes the page.
- Next.js 15 defaults to 0 seconds for dynamic routes, but 5 minutes for static routes.
- Use `router.refresh()` to manually trigger a fresh fetch from the client.
