Caching Strategies: Five Core Patterns
How your application reads and writes through the cache defines its behavior. There are five fundamental patterns, each with different trade-offs between consistency, complexity, and write performance. Cache-aside (lazy loading) is the most common. The application checks the cache first; on a miss, it loads from the database and populates the cache. The app owns the logic. Read-through pushes that responsibility to the cache layer — on a miss, the cache itself fetches from the database. Write-through writes to both cache and database synchronously, keeping them consistent but slowing every write. Write-behind (write-back) writes to the cache immediately and flushes to the database asynchronously — fast writes, but you risk data loss if the cache crashes before flushing. Write-around skips the cache on writes entirely, writing only to the database; the cache is populated on the next read.