📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you invalidate output cache entries when data changes, and how do you make that work across several instances?

Intermediate Theory Intermediate

🎯 Key points

  • Tag entries in the policy; EvictByTagAsync after writes
  • In-memory store is per instance: other instances stay stale until expiry
  • Redis output cache store (AddStackExchangeRedisOutputCache) shares entries and tag eviction
  • Output caching uses IOutputCacheStore, not IDistributedCache
  • Alternatives: short expiries, versioned keys, invalidation events via pub/sub
  • Evict after the write commits, not before

⏱ 30-second answer

Tag entries in the policy (.Tag("products")) and call IOutputCacheStore.EvictByTagAsync("products", ct) after a write. With the default in-memory store, eviction only affects the instance that handled the write, so other instances keep serving stale entries until they expire.

For several instances, use the Redis output cache store (AddStackExchangeRedisOutputCache from Microsoft.AspNetCore.OutputCaching.StackExchangeRedis, available since .NET 8 and current in .NET 10). Output caching uses its own IOutputCacheStore abstraction, not IDistributedCache, because it needs tag-based eviction.

Alternatives: short expiries where a little staleness is fine, versioned keys (vary by a data version so a write naturally misses), or publishing an invalidation event (Redis pub/sub, Service Bus) that each instance handles by evicting locally. The trade-off is freshness versus the cost of a shared store.

🔍 What the interviewer is checking

Checks they understand tag-based eviction and shared stores

↩ Usually asked after

More in Application Performance

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me