Layered Cache Demo
The fresh panel generates a new value on every request. The cached panel serves the same value until its 30-second TTL expires — watch the age counter to see the difference.
GET /api/demo/freshGET /api/demo/cached → L1 → L2L1 — Cache API
Per-datacenter. Sub-millisecond on a hit. Stored in the same physical location as the Worker handling the request.
L2 — Workers KV
Globally replicated key-value store. Backfills L1 on a miss. Survives edge restarts and spans every Cloudflare datacenter.
SWR strategy
Stale-While-Revalidate: when the TTL expires the next request still gets the cached response instantly, while the handler re-runs in the background.
Local dev (npm run dev): Nitro in-memory cache — caching works but not the real CF layers.
Local preview (npm run preview): Miniflare emulates KV + Cache API — full layered cache behaviour.
Deployed (npm run deploy): Real Cloudflare edge — L1 per-datacenter Cache API, L2 globally-replicated KV.