FIG_010 [ TIERED_CACHE ]
FIG_010 // Interactive Cutaway @durability/transforms

Tiered Cache

Composable 3-tier RPC caching with isolate LRU, Durable Object storage, shared PoP Workers Cache, singleflight, and SWR.

FIG_010 [ TIERED_CACHE ] LISBOA // 3-TIER
1 memoryTier (LRU) 2 durable / PoP 3 Singleflight / SWR
1 / 5
WARM (AGE 18s • FRESH): All 3 tiers filled — click Fresh Hit for instant 0ms Chafariz return, or test 5x Stampede, SWR, Evict, and 503 Stale-If-Error.
CACHEPLAN WINDOWS AGE: 18s • FRESH 0..30s FRESH 30..120s SWR 120..300s STALE-IF-ERR L1 • memoryTier CHAFARIZ • LRU 1-FLIGHT N → 1 L2 • durableTier MÃE D'ÁGUA • DO STORAGE L3 • workerCacheTier ÁGUAS LIVRES • SHARED PoP (serveCached) FRESH HIT 1 / 256 LRU FULL SURVIVES cfCache: HIT 1-FLIGHT SIPHON • L3→L2→L1 SLUICE: PoP ON ORIGIN DO • LIVE HOPS: 1 CANEÇAS SPRING CACHEPLAN AGE FRESH / SWR / 503 DATA IN / OUT STUB.WITH(TIERS) CHAFARIZ (L1) MEMORYTIER LRU REFILL SIPHON 1-FLIGHT WRITEBACK SLUICE BYPASS FALLBACK: 'RPC' ORIGIN DO CLICK: LIVE / 503 CANEÇAS PUMP MISS + SWR REFRESH WRITE-BACK REFILLS L3→L2→L1
CHAIN: stub.with(memoryTier).with(durableTier).with(workerCacheTier) • SINGLEFLIGHT + SWR + STALE-IF-ERROR
SPEC // 10 [ ARCHITECTURE ]
01 // What it’s for

Why reach for Tiered Cache

Use @durability/transforms Tiered Cache to keep hot Durable Object reads fast, cheap, and resilient to traffic spikes or origin blips. Declare per-method TTLs once in a cachePlan, then compose only the tiers each caller needs via stub.with(...).


02 // How it works

Inside your Durable Object

  1. 013 composable hydraulic tiers: memoryTier answers in 0ms from isolate RAM (LRU); durableTier persists inside the calling DO's storage to survive isolate eviction; workerCacheTier + serveCached share hits across an entire Cloudflare PoP.
  2. 02Singleflight stampede protection: Concurrent cold misses collapse into one upstream origin call whose result backfills every tier on the return path.
  3. 03Stale-While-Revalidate & Stale-If-Error: Within staleMs, callers receive an instant cached reply while one background probe refreshes Origin; on an Origin 503, staleIfErrorMs shields callers safely.
  4. 04Configurable PoP fallback: When a Workers Cache hop times out or errors, fallback: 'rpc' (default) bypasses directly to the origin stub—or set 'throw' to surface CachedCallError.
Tiers
Memory → DO Storage → PoP
Protection
Singleflight + SWR + 503 Shield
Import
@durability/transforms