PRO

Effect Cache Stampede Guard

A read-through cache that survives a hot-key expiry and a cold-start traffic spike, built on the Effect Cache. When a key is missing, concurrent lookups of that key are coalesced onto a single origin fiber (single-flight), so a thousand simultaneous misses cause exactly one database load instead of a thundering herd. A Semaphore wraps the origin lookup as an admission gate, so even a burst of distinct cold keys can never open more than the permit count of concurrent origin loads and melt the database. Stale entries are served immediately while a detached fiber refreshes them through Cache.refresh, so a slow origin never blocks a reader. Solves cache stampede and thundering herd. Pinned to effect 4.0.0-beta.98.

Install
npx shadcn@latest add @compronents/effect-cache-stampede-guard

Installs from ui.aryank.space. Needs a registry token and a one-time @compronents entry in components.json. The docs walk through both.

Visualization
guard
miss A
unknown
miss B
unknown
miss C
unknown
database
Origin
const value = yield* db.load(key) // every miss pays this

The hot key expires and every concurrent miss recomputes it independently: three misses become three identical database loads, and at real traffic a single expiry becomes thousands. Watch the database take one load per miss until it dies.

Files
Checking access…
Dependencies