← blog
NextjsNovember 27, 2026 · 16 min read

Next.js 16 use cache: remote vs use cache: private

Next.js 16's use cache: remote shares a cache across instances; use cache: private never leaves one request. Which to pick, plus a copy-paste cheat sheet.

Parsa Jiravand · Frontend engineer · building bestpractic
Next.js 16 use cache: remote vs use cache: private

A team ships personalized product recommendations on a product page. The data depends on the visitor's session cookie, so a teammate wraps the fetch in a plain 'use cache' function and reads cookies() inside it. next build passes. next start doesn't: every request to that route throws next-request-in-use-cache, because use cache cannot see request-time APIs at all, by design.

The fix looks obvious: switch to 'use cache: private', since the docs say it's the directive that can read cookies. It compiles, it renders, the recommendations are personalized again — and the team, having just learned there's a "private" cache, applies it everywhere else that used to be a plain fetch, including the currency-converted price that's genuinely the same for every visitor paying in USD. Three weeks later, the pricing API is getting hammered on every cold start in production, because 'use cache: private' was never meant to deduplicate shared data across users — it isn't that kind of cache at all.

This is the mix-up this article exists to prevent. Next.js 16 ships three caching directives under Cache Components — use cache, 'use cache: private', and 'use cache: remote' — and they answer three different questions, not one question three ways. This article is written against Next.js 16.4.6 (verified against the framework's own bundled documentation and npm's latest dist-tag in November 2026); both private and remote caches were introduced and stabilized together with Cache Components in Next.js 16.0.0.

By the end of this article you'll be able to:

  • Explain what each of the three use cache directives actually stores, and where
  • Pick the right one for personalized data, for shared-but-expensive data, and for everything else
  • Read the nesting rules that decide which directives can wrap which
  • Avoid the two opposite mistakes: caching personal data where it could leak, and caching shared data where it never gets reused

You're already caching something with plain 'use cache' — or you've read Next.js Cache Components Explained, which builds that foundation from nothing. This article assumes that part and goes one level deeper, into the two directives that exist specifically for data use cache can't handle. You don't need to have read it first; the rules below stand on their own.

Plain use cache does two jobs at once: it tells Next.js what's safe to put in a route's prerendered static shell, and it caches a function's result so repeat calls with the same inputs skip the work. Both jobs assume the same thing — that the cached value is identical for every visitor who triggers the same inputs. That assumption breaks the moment a value depends on who's asking, which is exactly why use cache refuses to let you read cookies(), headers(), or searchParams inside it: there'd be no safe single value to put in a shell every visitor shares.

So the framework splits the "who's asking" problem into two separate directives, one for each half of it:

  • Sometimes the answer genuinely differs per visitor and must never be handed to anyone else — that's 'use cache: private'.
  • Sometimes the answer is the same for many visitors (same currency, same language, same product category) but you still need to defer reading it until request time, and the default in-memory cache isn't durable enough across your server instances — that's 'use cache: remote'.

Neither one is "the private version" or "the bigger version" of the other. They answer different questions, and reaching for the wrong one either leaks nothing useful (over-caching data that was never personal) or hammers your backend (under-caching data that should have been shared).

The mental model: every cache in Next.js is the product of two independent choices — who the cached value is allowed to be shared with (scope), and where it physically lives (storage). Conflating these two dials is the whole source of confusion here.

use cache'use cache: remote''use cache: private'
Scope — who shares one entryEveryoneEveryoneNobody but this one request
Storage — where it livesIn-memory (or a configured handler)A remote cache handler (Redis, KV, …)Nowhere persistent — not saved across requests in production
Can read cookies() / headers()NoNoYes

Read the table by column, not by row: use cache and 'use cache: remote' share the same scope (everyone) and differ only in storage durability. 'use cache: private' is the odd one out on scope — it exists purely to let request-specific code participate in caching at all, and the tradeoff for that access is that nothing it produces gets saved across requests.

A quick recap, since both of today's directives are defined by contrast to this one. A plain cached function looks like this:

TypeScript
1
2
3
4
5
6
7
8
// app/lib/pricing.ts import { cacheLife } from 'next/cache'; export async function getBasePrice(productId: string) { 'use cache'; cacheLife('hours'); return db.products.getPrice(productId); }

This is shared across every visitor who asks for the same productId, and it can contribute to the route's static shell. The constraint: this function, and anything it calls, cannot touch cookies(), headers(), or searchParams — doing so throws next-request-in-use-cache the moment the route actually runs, even though next build may not have caught it.

Key concept: use cache isn't refusing to be "dynamic" out of caution — it genuinely has nowhere safe to put a per-visitor answer. That gap is exactly what the next two directives exist to fill, each for a different reason.

'use cache: private' lifts the ban on request-time APIs, at the cost of never sharing the result:

TSX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// app/product/[id]/page.tsx import { Suspense } from 'react'; import { cookies } from 'next/headers'; import { cacheLife, cacheTag } from 'next/cache'; export default async function ProductPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; return ( <Suspense fallback={<div>Loading recommendations...</div>}> <Recommendations productId={id} /> </Suspense> ); } async function Recommendations({ productId }: { productId: string }) { const sessionId = (await cookies()).get('session-id')?.value ?? 'guest'; const recs = await getRecommendations(productId, sessionId); return <RecList items={recs} />; } async function getRecommendations(productId: string, sessionId: string) { 'use cache: private'; cacheTag(`recommendations-${productId}`); cacheLife({ stale: 60 }); return db.recommendations.personalize(productId, sessionId); }

In production, calling this function twice within the same request can reuse the result — that's request-scoped deduplication, not a server cache. It is never written to a cache that a later request, from the same visitor or anyone else, can read. In development, Next.js does keep it in memory, keyed by that request's cookies and headers, so you can watch it serve a near-identical dev request from cache — which is useful for iterating locally, but isn't the production behavior.

Key concept: the stale time you set with cacheLife governs the client-side router cache, not a server store. Private cache functions are excluded from static-shell generation entirely, so this value only controls how long the browser can reuse what it already streamed down. The docs call out a specific threshold: stale must be at least 30 seconds for per-link prefetching to work, and at least 5 minutes for the content to be eligible for the route's App Shell. If a function only needs within-request dedup and shouldn't shorten the route's overall client stale time, set cacheLife({ stale: Infinity }) — that opts it out of influencing the route's shortest stale time without claiming server persistence it was never going to get.

'use cache: remote' solves a completely different problem: use cache's default in-memory store is just that — in-memory, per instance. In a serverless deployment, each invocation can land on a different, short-lived instance, so the in-memory cache barely helps; every cold instance re-runs the work and re-hits your backend.

TSX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// app/product/[id]/page.tsx import { Suspense } from 'react'; import { cookies } from 'next/headers'; import { cacheTag, cacheLife } from 'next/cache'; async function ProductPrice({ productId }: { productId: string }) { // Reading cookies defers this component to request time const currency = (await cookies()).get('currency')?.value ?? 'USD'; const price = await getProductPrice(productId, currency); return <div>Price: {price} {currency}</div>; } async function getProductPrice(productId: string, currency: string) { 'use cache: remote'; cacheTag(`product-price-${productId}`); cacheLife({ expire: 3600 }); // 1 hour // Cached per (productId, currency) — a handful of currencies, not one entry per visitor return db.products.getPrice(productId, currency); }

Notice what's 'use cache: remote', not 'use cache: private', in this example: the price depends on currency, which is read from a cookie, but currency is shared across potentially thousands of visitors. Caching it as "private" would create one cache miss per visitor for data that's identical across a whole currency; caching it as "remote" creates one shared entry per currency and lets every server instance hit that same entry.

A remote cache needs a real handler — Redis, a KV store, anything configured through cacheHandlers — which most hosting providers supply automatically, and which you configure yourself if you're self-hosting. That's the tradeoff 'use cache: remote' is explicit about: infrastructure cost and a network round trip on every lookup, in exchange for a cache that's actually shared once a request falls outside the static shell.

Key concept: reach for 'use cache: remote' only when the dimension you're caching on has few distinct values relative to your traffic (currencies, languages, categories — not user IDs or arbitrary search filters). The docs frame this as finding "the dimension with fewer unique values" and caching on that, then filtering the rest in memory. Cache on category, not on category + minPrice, and the hit rate difference is the entire point of paying for a remote handler at all.

Because remote and private caches solve opposite problems, Next.js enforces where each can appear relative to the other:

  • A remote cache can nest inside another remote cache, or inside a plain use cache.
  • A remote cache cannot nest inside a private cache, in either direction.
TSX
1
2
3
4
5
6
7
8
9
10
11
// VALID — remote inside a plain cache async function outerCache() { 'use cache'; return innerRemote(); // fine — resolved when deferred to request time } // INVALID — remote inside private, or private inside remote, throws async function outerPrivate() { 'use cache: private'; return innerRemote(); // Error }

The rule follows directly from the mental model: a private cache's entire contract is "nothing here gets shared." Letting a shared remote cache live inside it (or vice versa) would mean one of the two guarantees has to break. Next.js enforces the rule at the boundary instead of leaving it to be discovered in production.

  • Remote caches don't survive a deploy. The cache key for 'use cache: remote' includes your build ID (or deploymentId, if you've configured one), so a new build produces entirely new keys. This is intentional — a refactored function or an upgraded dependency can quietly change what a cache entry means, and reusing an old entry under a new build risks serving data that doesn't match what the new code expects.
  • Draft Mode bypasses use cache, no special case needed. The docs are explicit about plain use cache: with Draft Mode enabled, cached functions and components re-execute on every request and their results aren't saved to the cache. 'use cache: private' already never persists across requests in production, so Draft Mode doesn't change anything there either way. The docs don't make the same statement by name for 'use cache: remote' — don't assume it behaves identically without checking your own cache handler.
  • connection() is off-limits in both use cache and 'use cache: private'. It's easy to assume "private" means "anything request-related is now fair game," but connection() specifically carries connection-level information that isn't safe to cache even per-request, so it stays prohibited in both.
  • You can't configure a custom handler for 'use cache: private'. Unlike use cache and 'use cache: remote', there's no cacheHandlers hook for the private directive — by design, since it's defined by not persisting anywhere durable.
  • "Private" and "needs a database row per user" aren't the same problem. If what you actually need is data that survives across a user's many requests (not just within one), none of these three directives is the tool — that's your own data layer, read directly or behind a conventional cache.

  • Default to plain use cache for anything that's genuinely identical for every visitor. It's the cheapest of the three — no extra infrastructure, and it's eligible for the static shell.
  • Reach for 'use cache: remote' only once you've confirmed the dimension you're caching on has low cardinality (a handful of currencies or categories, not one value per user) and the operation is slow or rate-limited enough to justify a network round trip to check.
  • Reach for 'use cache: private' only for data that's genuinely personal and either can't be refactored to read runtime values outside the cached scope, or has a real compliance reason it must never land in a shared store — the docs call this the narrow case, not the default.
  • Before adding any directive, ask whether the runtime value can simply be read outside the cached function and passed in as an argument. That's the preferred pattern for both use cache and 'use cache: remote', and it often removes the need for 'use cache: private' entirely.
  • Set an explicit cacheLife on every cache you write. The implicit default profile (5 minutes client-side stale, 15 minutes server-side revalidate) is a reasonable fallback, but it hides the lifetime at the call site — and for private caches specifically, forgetting it means forgetting to decide whether this function should shorten the whole route's client stale time.

Runs right in your browser — poke at it and watch the concept react live.

  • use cache, 'use cache: private', and 'use cache: remote' answer three different questions — shared/durable, personal/ephemeral, and shared/durable-but-deferred — not three strengths of the same cache.
  • 'use cache: private' lets you read cookies(), headers(), and searchParams inside a cached scope, but in production it never persists past the request that created it. It solves an access problem, not a sharing problem.
  • 'use cache: remote' solves the opposite problem: it shares a cache entry across every server instance, using a real handler, at the cost of infrastructure and network latency — and it only pays off when the cached dimension has few distinct values relative to your traffic.
  • Remote and private caches cannot nest inside each other in either direction, because their guarantees are mutually exclusive.
  • The cheapest fix for "I need runtime data in a cached function" is still reading it outside the cache and passing it as an argument — reach for private or remote only once that's genuinely not an option.

That team from the opening: the actual fix wasn't choosing between 'use cache: private' and 'use cache: remote' for the pricing function — it was recognizing that currency isn't personal data at all. The recommendations stayed on 'use cache: private', keyed per session, exactly as personal data should be. The price moved to 'use cache: remote', keyed on currency — a few dozen cache entries instead of one cache miss per visitor, and their pricing API went back to seeing the traffic it was built for.

Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.

Not nested inside one another, in either direction — Next.js rejects that at the boundary. You can use both in the same route, on different functions, as the pricing-and-recommendations example above does; you just can't wrap one directive's scope inside the other's.

No. Its cache key includes your build ID (or deploymentId if configured), so every new deploy invalidates every entry by construction. If you need data that survives a deploy, that's a job for unstable_cache (for non-fetch functions) or the fetch cache, not either of today's two directives.

Because that's the entire point of the directive. It isn't a bug or a cold-cache miss — 'use cache: private' is explicitly designed to never share its result across requests in production. If you need the same computed value available to a second request, you want use cache or 'use cache: remote' instead, with the request-specific part extracted and passed in as a plain argument.

Both can persist data outside the in-memory default, but they come from different eras of the same problem. unstable_cache() predates Cache Components, has its own key-building rules (notably, no awareness of root params), and the docs now point most use cases toward use cache and its Cache-Components-era siblings instead. If you're still using unstable_cache() for something that could be a cached function today, a cold-start cache-key leak between the two is worth reading about before you decide which one to keep.

Usually not — most hosting providers wire up a default remote handler for you. You only need to configure cacheHandlers yourself if you're self-hosting and want remote caching, or if you want to swap in a specific store (Redis, a particular KV service) instead of whatever your platform provides by default.

The implicit default profile applies: 5 minutes stale (client-side), 15 minutes revalidate (server-side), and no time-based expire. It's a safe fallback, but for a private cache specifically, it also means you haven't deliberately decided whether this function should be allowed to shorten the whole route's client-side stale time — set it explicitly once you know the answer.

TEXT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
NEXT.JS 16 CACHE DIRECTIVES — WHICH ONE? use cache use cache: remote use cache: private Shared across users? yes yes no Can read cookies/headers? no no yes Where it's stored in-memory* remote handler nowhere durable Survives a deploy? no no n/a Needs cacheHandlers? optional yes (or platform) not configurable Contributes to static shell? yes when static never * or a configured handler — see cacheHandlers DECISION ORDER (ask in this order, stop at the first "yes"): 1. Can I read the runtime value OUTSIDE the cache and pass it in as an argument? → yes: use plain `use cache`. Done — you probably don't need private or remote. 2. Is the value genuinely personal / per-user, with no low-cardinality dimension to cache on instead? → yes: `use cache: private`. Set cacheLife({ stale: Infinity }) if it's pure within-request dedup and shouldn't shorten the route's client stale time. 3. Is the value shared across many users, deferred to request time, and worth paying infra + latency for a real cache hit (slow/rate-limited/expensive)? → yes: `use cache: remote`, keyed on the LOW-cardinality dimension (currency, locale, category) — never on something unique per request. 4. Otherwise: plain `use cache` with an explicit cacheLife. NESTING remote inside remote -> OK remote inside use cache -> OK remote inside private -> ERROR private inside remote -> ERROR next.config.ts (required for all three) export default { cacheComponents: true, }

🚀 Want more like this? Every guide, playground, and quiz lives on bestpractic.org — open it and sign up free so the next one finds you.

Thanks for reading! Let's stay connected:

Keep reading

One post a day, in your inbox

Each one with a runnable playground and a quiz. No pitch, no digest, unsubscribe in one click.

0 comments

Sign in to join the discussion, like comments, and save articles for later.