Caching interview question · Most asked

How does stale-while-revalidate work, and when is it inappropriate?

Summary

After a soft expiry, the cache keeps serving the old value while one background refresh rebuilds it, avoiding stampedes and latency spikes. It's inappropriate for data that must be exactly current, like stock at checkout or permissions.

Longer Answer

Available in HTTP (Cache-Control: stale-while-revalidate), in libraries (Caffeine refreshAfterWrite, Laravel Cache::flexible) and easy to build with a soft-expiry timestamp inside the value.

Key Points

  • Serve stale, refresh once
  • Prevents stampedes
  • Not for must-be-fresh data

Deep dive: Database Caching at Scale

More most-asked Caching questions

← All Caching questions