Caching trades freshness for latency. A cache only helps when the read pattern is hot, the freshness tolerance is known, and the invalidation path is explicit.
Key ideas
- Cache-aside: app reads cache, on miss loads the DB and backfills the cache.
- Write-through / write-back: writes go through the cache; stronger freshness, more complexity.
- A CDN caches static and cacheable responses at the edge, close to users.
Compare
| Strategy | Tradeoff |
|---|---|
| Cache-aside + TTL | Simple, eventual freshness; stale window equals the TTL |
| Write-through | Fresh reads, slower writes |
| No cache | Always fresh, full DB load |
Warning
A cache without an invalidation plan just moves the bug closer to your users.