ASP.NET Core Web API Interview Question #138

What is cache invalidation?

Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced

Quick Interview Answer

Cache invalidation removes or replaces cached data when it is no longer valid. Common strategies include time-based expiration, explicit removal after writes, versioned keys, and event-driven invalidation.

Detailed Explanation

Cache invalidation removes or replaces cached data when it is no longer valid. Common strategies include time-based expiration, explicit removal after writes, versioned keys, and event-driven invalidation.

Caching is safe only when the application has an acceptable staleness model. Long cache lifetimes without a deliberate invalidation strategy can make an API return incorrect data.

Code Example

await _service.UpdateProductAsync(id, request, token);

_cache.Remove($"product:{id}");

return NoContent();