Software Engineer
hardcaching-strategies-and-invalidation
What are common caching strategies and how do you handle cache invalidation?
Answer
Common caching patterns:
- **Cache-aside:** app reads from cache, falls back to DB, then populates cache.
- **Read-through:** cache layer loads from DB on miss.
- **Write-through / write-behind:** writes go through cache (sync/async) before DB.
**Invalidation options:**
- TTL/expiration
- explicit deletes on writes
- versioned keys (e.g., `user:v3:123`)
**Interview tip:** explain trade-offs between freshness, complexity, and performance.
Related Topics
CachingSystem DesignPerformance