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.
Check your understanding
Cache-aside vs write-through?Show answerHide answer
Answer
Cache-aside: app loads DB on miss. Write-through: writes update cache and DB together for fresher reads at write cost.What is the risk of write-behind?Show answerHide answer
Answer
Fast writes to cache with async DB flush — data loss if the cache dies before flush.When is write-around sensible?Show answerHide answer
Answer
Write-heavy paths where caching the write is pointless and you prefer populate-on-read.