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.
npx shadcn@latest add https://ui.aryank.space/r/effect-cache-stampede-guard.jsonInstalls from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.
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.