Public versus private cache
What you need to know
Cache isolation starts by distinguishing public data from identity-dependent data. Shared public entries may be reused across visitors, but access-controlled data should stay behind an authorization boundary and outside the public cache.
By the end, you can: identify identity-dependent data; test two distinct users.
Separate public projection and private policy
type Book = { id: string; title: string; internalCost: number };export function publicBook(book: Book) { return { id: book.id, title: book.title };}console.log(publicBook({id:'fern', title:'Fern Atlas', internalCost:7}));Expected behavior: Only id and title appear in the resulting object. A real public reader must also ensure the source record is approved for publication.
How it works
A public catalog record has the same approved representation for every visitor in a category. A draft, private reading list or negotiated price depends on verified identity, tenant, policy or entitlement. A TypeScript type does not remove sensitive fields and a tag does not enforce access. Project a public DTO from approved fields and cache only that DTO. Request memoization, server data cache, rendered output, client navigation state and HTTP/CDN storage are distinct layers; disabling HTTP storage alone does not undo a server cache leak. A private endpoint can send Cache-Control: private, no-store while separately keeping its data read outside shared cache scopes. Never make a secret or raw credential part of a public cache key. For exceptional private caching designs, verify policy changes, namespace isolation, revocation and storage rights first. The core lab deliberately avoids cross-request private caching.
Private response header in a Route Handler
// Partial authorized response helper; caller must verify access first.export function privateResponse(list: { title: string }[]) { return Response.json(list, { headers: { 'Cache-Control': 'private, no-store' } });}Expected behavior: HTTP storage is prohibited for this response; this header does not configure Next.js internal cache scopes.
Common mistake
Using a generic shared key such as reading-list returns one visitor’s data to another. Prefixing a key with a tenant does not itself enforce ownership. Keep private data uncached across requests in the core example.
Practice and verification
Inspect the fixture model with two synthetic tenants and the same book identifier. Confirm only public titles use the shared store. Check private requests with missing, foreign and authorized identity before an integrated release.
Scope: App Router, proposed Next.js 16.x and React 19, Cache Components enabled in a separate fixture. Framework snippets are staged and not executed; local pure models are not framework evidence. Exact patched dependencies and platform contracts are pending.