.NET Architecture & System Design Interview Question #31
What is cache invalidation?
Caching, CDN, Queues & Asynchronous Processing Junior Beginner
Quick Interview Answer
Cache invalidation is the process of removing or updating cached data when it is no longer valid. It is one of the most difficult parts of caching because incorrect invalidation can return stale information.
Detailed Explanation
Cache invalidation is the process of removing or updating cached data when it is no longer valid. It is one of the most difficult parts of caching because incorrect invalidation can return stale information.
Common strategies include time-based expiration, explicit removal after writes, versioned keys, event-driven invalidation, and accepting bounded staleness for data where perfect freshness is unnecessary.
Code Example
await repository.UpdateAsync(product);
await cache.RemoveAsync(
$"product:{product.Id}");