Caching

Caching stores the result of an expensive computation or remote call in a fast, nearby location so subsequent requests for the same data are served without redoing the work. Caches operate at many layers, including CPU cache, OS page cache, database buffer pool, application cache, CDN, and browser cache.

How it works

A cache is a key-value store in front of a slower source of truth. When a request arrives, the cache is checked first. A hit serves the request directly; a miss falls through to the source, and the result is typically written back to the cache. Eviction policies (LRU, LFU, ARC) decide what to drop when the cache is full. TTL values govern how long entries remain valid.

Variants

  • Cache-aside (lazy loading). Application checks cache, falls through to source on miss, writes result back.
  • Write-through. Writes go to cache and source synchronously.
  • Write-behind (write-back). Writes hit cache; cache flushes to source asynchronously.
  • Refresh-ahead. Cache proactively refreshes hot entries before they expire.
🔗

Subscribe to Sahil's Playbook

Clear thinking on product, engineering, and building at scale. No noise. One email when there's something worth sharing.
[email protected]
Subscribe
Mastodon