Distributed cache consistency
What you need to know
Distributed-cache consistency means different application replicas must agree on which public data is reusable or stale. A cache in one Node process does not automatically communicate invalidation to another.
By the end, you can: compare replica-local and shared storage; design invalidation test.
Trace two isolated replicas
A cache: edition 1 | B cache: edition 1Origin commits edition 2A evicts local key -> A reads 2B has no signal -> B can still read 1Shared invalidation generation increments -> both old entries are rejectedExpected behavior: The last step requires both replicas to consult or receive the same reliable generation.
How it works
Imagine replica A and B have both cached edition 1. A title is changed to edition 2 and A drops its local entry. B can still return edition 1 if it has no invalidation signal. A shared storage adapter or reliable tag-generation propagation can address this, but neither proves correctness without tests. Separate deployment namespaces so incompatible outputs are not mixed. In Next.js the singular cacheHandler config concerns server cache operations such as ISR, while cacheHandlers (plural) configures handlers for the cache directives. Do not swap these APIs. Review documented methods, tags, expiration, serialization, replication and error behavior for the exact release. A late origin fill that started before invalidation can reintroduce an old value unless the design guards against it. The model uses a generation captured at fill start and refuses to store a value if that generation changed. In a real concurrent store, comparing the generation and publishing the entry must be atomic, or a generation-specific key must prevent old fills from becoming current. A separate check followed by an unguarded write can race with invalidation. This is an application-level consistency example, not the actual Next.js cache key or adapter contract.
Reject a fill started before invalidation
function acceptFill(startGeneration: number, currentGeneration: number) { return startGeneration === currentGeneration;}console.log(acceptFill(4,4), acceptFill(4,5));Expected behavior: true false. The second fill cannot publish into the new generation under this simplified model.
Common mistake
A shared cache is not automatically strongly consistent. Network partitions, delayed tag propagation, stale database replicas and key collisions still matter. Do not claim a local simulation demonstrates actual Redis or Next.js handler behavior.
Practice and verification
Run the two-replica model tests for local divergence, shared invalidation, late fill and namespace separation. Design a future real two-process test with an approved handler, including restart and invalidation delivery failure.
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.