Alle artikler
18. november 2026

Next.js caching layers: what is cached, where and for how long, 2026

Next.js caches in five places, and each has its own lifetime. A map of what lives where, which defaults apply and how to control each layer.

Abstract flow of connected boxes and arrows with one acid step on a dotted canvas
Illustration: Kallos Labs.

Next.js caches in five places: memoization during one render, a server-side cache for data, use cache entries, prerendered HTML, and the browser. Each has its own storage and lifetime, which is why a page can look stale in one place and fresh in another. As of November 2026, the docs describe two models, Cache Components and the previous one, and this article maps both.

The five layers at a glance

LayerWhere it livesHow long it lastsHow you control it
Request memoizationServer memory, one render passUntil that render endsAutomatic for fetch GET, React.cache for the rest
Data cache (previous model)Server-side persistent cacherevalidate seconds, or indefinitelycache, next.revalidate, next.tags, unstable_cache
use cache entries (Cache Components)In-memory store by default, or a cache handlerSet by cacheLife, default profile if omitteduse cache, cacheLife, cacheTag
Prerendered HTML and static shellDisk when self-hosting, or platform storage behind a CDNUntil revalidated or the next deploycacheLife, revalidate, generateStaticParams
Browser router cacheBrowser memoryThe stale window, 30 seconds minimumcacheLife stale

The rest of this article walks through each row.

Request memoization

Memoization removes duplicate work inside a single render. According to the fetch reference, GET requests with the same URL and options are memoized during a server render pass. Call the same fetch in a layout, a page and generateMetadata, and Next.js runs it once. If you want the full picture of how metadata functions share data, see our guide to generateMetadata.

Three limits are worth knowing:

  • It lasts a single render pass. The docs separate it from persistent caching: "memoization lasts only for a single render pass, while cached responses persist across requests."
  • It does not apply in Route Handlers, because they are not part of the React component tree.
  • It covers fetch only. For an ORM or direct database call, wrap the function in React's cache to deduplicate within a render.

The previous model: fetch, unstable_cache and segment config

If you have not enabled cacheComponents, you are on what the docs call the previous model. Caching is opt-in here.

fetch defaults

A fetch request is not cached by default. Set cache: 'force-cache' to cache it, or next: { revalidate: 3600 } to cache it for 3,600 seconds. The fetch reference adds details worth knowing:

  • A cached request matches on URL, method, headers and body, so requests that differ in any of them are stored separately.
  • Only responses with a 200 status are stored.
  • With no cache option, a route that reads no request-time APIs is prerendered, so the request runs once during next build. If the route reads a request-time API such as cookies(), it runs on every request.

unstable_cache and route segment config

For database queries and other non-fetch work, unstable_cache takes a cache key, tags and a revalidate value in seconds. At the route level, export const revalidate accepts false (the default, equivalent to caching indefinitely), 0 (always dynamic) or a number of seconds. The lowest revalidate across a route's layouts, pages and fetches sets the frequency for the whole route. The value must be statically analyzable: revalidate = 600 works, 60 * 10 does not.

In development, pages are always rendered on demand and never cached, so a caching problem that only appears in production is common.

use cache: the Cache Components model

Cache Components arrived in Next.js 16. The use cache directive was introduced as experimental in v15.0.0 and stabilized in v16.0.0. You enable it with cacheComponents: true in next.config.ts, and new apps from create-next-app already have it on.

Checklist diagram with three items: stale, revalidate and expire
Checklist: use cache: the Cache Components model.

Cache key and default profile

use cache caches the return value of an async function or component. The cache key combines the build ID (or deploymentId if you set one), a function ID and the serializable arguments. Values captured from an outer scope become part of the key too, so different inputs get separate entries.

Pair every directive with cacheLife. Without it, the default profile applies:

  • stale: 5 minutes, on the client
  • revalidate: 15 minutes, on the server
  • expire: never, by time
import { cacheLife, cacheTag } from 'next/cache'

export async function getProducts() {
  'use cache'
  cacheLife('hours')
  cacheTag('products')
  return db.query('SELECT * FROM products')
}

Runtime behavior and hosting

Where the entry lives depends on where you host. By default, runtime entries sit in a per-instance, in-memory LRU store. The docs state that on serverless, entries "typically don't persist across requests", while build-time caching works normally. Self-hosted servers keep entries across requests, and cacheMaxMemorySize controls the size. For durable, shared storage, use cache: remote hands entries to a cache handler, at the cost of a network roundtrip on each lookup.

Cached scopes cannot call cookies(), headers() or read searchParams. Read them outside, then pass the values in as arguments.

A new deploy starts fresh. Because the key includes the build ID, entries do not carry over, even durable remote ones. For data that must survive a deploy, the docs point to unstable_cache or the fetch cache.

Prerendered HTML and the static shell

At build time, Next.js renders each route. With Cache Components, cached results and anything computed from predictable values land in a static shell, and uncached work behind <Suspense> streams at request time. This is Partial Prerendering, the default with Cache Components.

The caching guide says where this output is stored: prerendered HTML sits on disk when you self-host, or in your platform's durable storage behind a CDN. revalidate and expire decide when it is rebuilt. For routes with dynamic params, generateStaticParams prerenders the URLs you list, and other URLs are filled in after the first visit. Our write-up on incremental static regeneration covers that path in detail.

The browser router cache

Navigation keeps its own copy. When a client navigation or prefetch brings back an RSC payload, the browser keeps it fresh for the stale window from cacheLife. The client router enforces a minimum stale time of 30 seconds, and the x-nextjs-stale-time response header carries the lifetime from server to client.

use cache: private results live only in the browser. Calling a revalidation function from a Server Action clears the whole client cache immediately, regardless of the stale time.

Revalidation

Time-based revalidation is stale-while-revalidate. According to the revalidation guide, cached content is served immediately and a background regeneration starts once its age passes the cacheLife or revalidate duration. Stale content keeps being served until the fresh version is ready.

On-demand revalidation invalidates by tag or path:

  • Tag the data with cacheTag (or next.tags on fetch), then call revalidateTag or updateTag after a mutation.
  • revalidatePath invalidates through route-based soft tags.
  • The current docs show revalidateTag('user', 'max'), with a second argument naming a cache profile.

Run more than one instance and the picture changes. Revalidation events are local by default, so calling revalidateTag on one instance leaves the others serving stale content until a shared cache handler coordinates them. HTML and RSC payloads should also be cached together with the same lifetime if a CDN sits in front.

Which layer to reach for

Match the layer to the job:

  • Same data needed in several components of one page: rely on memoization or React.cache.
  • Shared data that changes on a schedule: use cache with an explicit cacheLife.
  • Data that changes on an edit: add cacheTag and invalidate after the mutation.
  • Per-user data: read the cookie outside the cached scope and pass it in, or stream it behind <Suspense>.
  • Not sure what is happening: run with NEXT_PRIVATE_DEBUG_CACHE=1 for verbose cache logs.

The right mix also depends on what you are building. A content site and a logged-in app cache very differently, which we cover in marketing site versus dashboard architecture.

Conclusion

Most caching surprises come from losing track of where a copy lives. Memoization ends with the render, the server store follows cacheLife or revalidate, the static shell follows the deploy, and the browser follows stale. Set cacheLife explicitly, tag what you will need to invalidate, and treat serverless and multi-instance hosting as the cases where defaults surprise you. If you want a second pair of eyes on a caching setup, contact Kallos Labs.

Frequently asked questions

Is fetch cached by default in Next.js?

No. In the current docs, fetch is not cached by default. You opt in with cache: 'force-cache' or next.revalidate. A route that reads no request-time APIs is prerendered, so an uncached fetch still runs once during next build.

How long does use cache keep data if I do not call cacheLife?

The default profile applies: stale for 5 minutes on the client, revalidate after 15 minutes on the server, and no time-based expiry. The docs recommend setting cacheLife explicitly so the lifetime is visible at the call site.

Does use cache work on serverless hosting?

Build-time caching works normally. The default in-memory store typically does not persist across requests on serverless, so entries may be recomputed. use cache: remote or a custom cache handler gives durable sharing across instances.

Does a new deploy clear the cache?

For use cache, yes. The cache key includes the build ID, or deploymentId if you configure one, so entries do not carry over to a new deploy, including remote ones.