
Master Next.js App Router caching by understanding request memoization, data cache, full route cache, and router cache behavior.
When I first started building full-stack applications with the Next.js App Router, the caching system felt like a bit of a moving target. Data would sometimes update instantly after a mutation, while other times it seemed stuck in the past, refusing to reflect database changes. If you have spent any time building production apps with React and Next.js, you have probably run into this exact puzzle.
Caching in the App Router is powerful because it makes your pages lightning fast by default. But that same performance can turn into a headache if you do not understand the four distinct caching mechanisms working behind the scenes.
Today, I want to break down these caching layers in plain English, show you how they interact, and share some practical patterns I use when building web apps for clients worldwide.
To master Next.js caching, you need to realize there isn't just one cache—there are four separate caches operating at different levels of your application. Let's look at them from the server down to the client.
Request memoization is a React feature, not strictly a Next.js feature, but it integrates deeply into the App Router. When you fetch the same data multiple times within a single React render tree—such as in a layout, a page, and multiple components—React automatically memoizes the function call.
// If you call this function multiple times in one render pass...
async function getUser(id: string) {
const res = await fetch(`https://api.example.com/users/${id}`);
return res.json();
}
// ...React only executes the network request once.
You do not need to manually pass props down a massive tree or set up a global state management library just to avoid duplicate API calls during a single page load. Request memoization handles this automatically for fetch requests.
Next.js has a built-in Data Cache that persists the results of data fetches across incoming server requests and deployments. This is where things get interesting for dynamic web applications.
By default, fetch requests in the App Router are cached indefinitely:
Tagged with
Leave a comment
// This is cached by default
const res = await fetch('https://api.example.com/posts');
If your data changes frequently, you can opt out of caching or configure revalidation:
// Revalidate the data every 60 seconds
const res = await fetch('https://api.example.com/posts', {
next: { revalidate: 60 }
});
// Completely dynamic, fetch on every request
const res = await fetch('https://api.example.com/posts', {
cache: 'no-store'
});
Next.js automatically renders and caches your static routes on the server at build time. When a user requests a static page, Next.js serves the cached HTML and React Server Component payloads instantly.
For dynamic routes—like pages that use cookies(), headers(), or search parameters—Next.js switches to server-rendering on demand. The resulting output is still cached for that specific request lifecycle, but it is not aggressively pre-rendered at build time.
On the client side, Next.js maintains an in-memory cache called the Router Cache. As a user navigates around your web app, the RSC payload of visited routes is stored in the browser.
When the user clicks a link to go back to a previous page, Next.js instantly renders it from the client-side router cache without making a new network request. This gives your app that snappy, single-page-application feel.
Working with these layers means you will occasionally need to invalidate or bypass the cache. Here are the two most common tools for the job: revalidatePath and revalidateTag.
When a user updates their profile or submits a form, you want to clear the cache for that specific page immediately. You can do this inside a Server Action:
'use server';
import { revalidatePath } from 'next/cache';
export async function updateProfile(formData: FormData) {
// Update database here...
// Clear the cache for the profile page
revalidatePath('/profile');
}
Tag-based revalidation is even more flexible. You can tag your fetch requests and clear multiple cached items that share the same tag across your application:
// Tag the fetch request
const res = await fetch('https://api.example.com/posts', {
next: { tags: ['posts'] }
});
// Later, in a Server Action after creating a new post:
revalidateTag('posts');
This pattern is especially useful in content-heavy platforms or dashboards where a single database mutation affects multiple UI components scattered across different pages.
Over many projects, I have developed a few simple rules to keep Next.js caching from causing unexpected bugs:
no-store or short revalidation intervals for authenticated user dashboards or real-time data.revalidatePath or revalidateTag to keep your UI in sync.Mastering these patterns takes a little practice, but once it clicks, you can build web applications that load instantly while remaining fully dynamic and accurate.
Need help building a high-performance web application or SaaS product using Next.js? Let's talk about your project—get in touch.