Cache tags and remote storage
What you need to know
A cache tag is a label linking cached results to a domain change, such as a catalog edition update. A storage handler determines where cached entries live; a tag is neither the cache key nor a permission rule.
By the end, you can: tag public data by domain; separate storage adapter from directive.
Attach domain tags to a public item
import { cacheLife, cacheTag } from 'next/cache';export async function book(id: 'fern' | 'river') { 'use cache'; cacheLife('hours'); cacheTag('catalog', `book:${id}`); return { id, title: id === 'fern' ? 'Fern Atlas' : 'River Walk' };}Expected behavior: The fern entry is linked to catalog and book:fern. The river entry has a distinct item tag.
How it works
Use a shared catalog tag for list views and a separate item tag for a detail read. If both show a title, an update should invalidate both relevant dependency groups. Derive tag values from validated internal IDs; do not let callers invalidate arbitrary tags. A normal use cache scope can attach tags through cacheTag. The remote directive is a separate documented option for remote storage through the configured cache handler; its name alone does not provide a shared service. Confirm the adapter, namespace, serialization, timeout, capacity and invalidation behavior. The private directive is a distinct documented option involving runtime request data; verify its maturity and exact client/server behavior before adoption. It is not used in the core lab. Do not assume it solves application authorization. This lesson uses ordinary public caches and no remote dependency. The handler implementation is a separate integration task, not a config name that can be guessed. The documented cacheHandlers (plural) option configures use cache backends; cacheHandler (singular) covers other server cache paths such as ISR. The default process-local memory cache is not shared across replicas. An external CDN may require its own purge of relevant HTML and RSC variants. Test each layer separately.
Plan a remote cache lane before enabling it
Scope: public catalog onlyHandler: approved shared service, exact package pendingNamespace: application + deployment generationChecks: cross-instance hit, tag propagation, timeout, bounded capacityFailure: controlled origin fallback or explicit unavailable resultExpected behavior: This is a design checklist, not a working distributed cache or a configured adapter.
Common mistake
A remote directive without a verified shared handler is not proof of multi-instance consistency. Do not use tags to grant access, or use raw credentials as tag values.
Practice and verification
For list, detail and related-title pages, draw which tags are attached and which are invalidated by a title change. Read the remote/private directive documentation for the exact release before extending the fixture.
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.