Cache invalidation strategies focus on removing or updating stale data from the cache when the source of truth (e.g., DB) changes:
Strategy | Description | Pros/Cons |
---|---|---|
Explicit Invalidation | Manually remove/update cache on data change | Precise but needs app-level logic |
TTL (Time-to-Live) | Items expire after fixed time | Easy, but can serve stale data |
Versioned Keys | Use version in cache key, change version to invalidate | Avoids collisions, but uses more memory |
Event-based Invalidation | DB changes publish events to update caches | Good for distributed systems |
Write-through/Write-behind | Auto-updates cache during writes | More consistent, but write-heavy |