PATTERN Cited by 1 source
Pluggable cache handler¶
Pattern¶
A framework's caching layer exposes a single setter
(setCacheHandler(impl) or equivalent) that accepts any
implementation of a small cache interface, letting the
deployment pick the right storage trade-off without
framework-level changes.
Forces¶
- Different applications have different cache requirements — small vs large payloads, frequent vs infrequent revalidation, strong vs weak consistency, per-deployment region affinity.
- Different platforms provide different cache primitives — Cloudflare KV, R2, Cache API, Redis, S3, …
- Framework shouldn't pick one; the deployment should pick.
- Users should not have to re-implement the framework's
caching semantics (revalidation windows, ISR, tagged
invalidation) in each handler — the contract should be
storage primitives (
get(key),set(key, value, ttl),delete(key)) not caching-semantics primitives.
Solution shape¶
// Framework
interface CacheHandler {
get(key): Promise<CacheEntry | null>;
set(key, entry): Promise<void>;
delete(key): Promise<void>;
}
setCacheHandler(impl: CacheHandler): void;
The framework implements the caching semantics (revalidation logic, ISR, invalidation); the handler implements only the storage layer.
Canonical application — vinext¶
import { KVCacheHandler } from "vinext/cloudflare";
import { setCacheHandler } from "next/cache";
setCacheHandler(new KVCacheHandler(env.MY_KV_NAMESPACE));
Named alternatives per the 2026-02-24 launch post:
- KV (default via
KVCacheHandler). - R2 — better for large cached payloads.
- Cloudflare Cache API — forthcoming lower-config alternative.
Consequences¶
- Deployment flexibility — each app picks the right storage primitive.
- Framework stays agnostic to platform cache substrate.
- Cache handlers are simple to write — the complex semantics stay in the framework.
- Cross-platform portability — the same framework runs
anywhere a
CacheHandlercan be implemented. - Requires the framework to define a stable cache handler contract it can evolve without breaking handlers.
Seen in¶
- sources/2026-02-24-cloudflare-how-we-rebuilt-nextjs-with-ai-in-one-week
— canonical wiki instance. vinext inherits
setCacheHandlerfrom Next.js's interface design and shipsKVCacheHandleras the default Cloudflare-backed implementation, while explicitly positioning R2 + Cache API as alternatives.
Related¶
- systems/vinext — host framework.
- systems/vinext-kv-cache-handler — the default implementation.
- systems/cloudflare-kv / systems/cloudflare-r2 — alternative substrates.
- concepts/incremental-static-regeneration — the caching semantics the handler powers.