Skip to content

Lesson 4 of 9 · 28m

The Four Caches You Are Actually Using

Next.js caching is not one cache: understand the request memoization, data cache, full route cache, and router cache before touching config flags.

The number one production complaint about App Router Next.js is not that caching exists. It is that people cannot say which cache produced the response they are looking at. There are four distinct layers, each with different scope and lifetime. Learn the layers and the system becomes mechanical; treat it as one blob and every deployment is a séance.

The four layers

  1. Request memoization — identical fetch calls within one server render are deduplicated. Lifetime: one render.
  2. Data cache — cached fetch responses persisted by the framework across requests and deployments depending on platform. Lifetime: until revalidated or redeployed in common hosts.
  3. Full route cache — prerendered HTML and RSC payload for a route. Lifetime: until invalidated or rebuilt.
  4. Router cache — client-side in-memory route payloads from prefetch/navigation. Lifetime: seconds to the session, depending on static versus dynamic behavior.

They compose. A page can have fresh data but stale full-route output, or fresh route output behind a client router cache that has not expired.

Defaults changed; read your version

Modern Next.js moved away from aggressively caching every fetch by default. In current versions, fetch is uncached unless you opt in:

await fetch("https://status.example.test/api", {
  next: { revalidate: 300, tags: ["status"] },
});

Route-level config still controls the rendering mode:

export const dynamic = "force-dynamic";
export const revalidate = 60;

Do not copy configuration from a Next.js 13 blog post into a current application. The flags look the same while defaults and semantics shifted underneath them.

Static versus dynamic is discovered, not wished into existence

Reading cookies, headers, search params, or uncached request-specific data generally makes a route dynamic. cookies() and headers() are async in current versions:

import { cookies } from "next/headers";

const jar = await cookies();
const session = jar.get("session")?.value;

Build logs print whether routes are static (○), static with revalidation (●/ISR depending on output), or dynamic (ƒ). Read them during deployment review. A route that silently became dynamic can turn a trivial traffic spike into database load.

The browser cache is a separate citizen

Cache-Control on route handlers and static assets matters independently of the framework cache. Immutable hashed assets should be cached for a year; personalized HTML should not be publicly cacheable. Do not expect Next.js data cache behavior to protect you from a CDN caching Set-Cookie responses incorrectly.

Field notes

  • unstable_noStore() and noStore() examples are version-sensitive; prefer explicit dynamic APIs and consult the version you actually run.
  • fetch memoization keys include URL and options. Two calls that differ only in header shape may not dedupe.
  • Database queries are not automatically memoized like fetch. Wrap repeated access deliberately with React.cache() where appropriate.
  • If localhost behaves differently from production, check the platform cache implementation before blaming application code.

Was this lesson helpful?

Sign in to rate