Problem Statement
Which technique best mitigates a cache stampede (dogpile) on popular keys?
Explanation
A single-flight guard lets only one worker rebuild a value while others serve stale data or wait briefly. Proactive refresh before expiry plus jitter avoids many keys expiring at once.
This keeps origin stable during spikes or cold starts.
Code Solution
SolutionRead Only
if(lock.try(k)){ v=recompute(); cache.set(k,v,ttl+jitter); lock.release(k); }