IMemoryCache, IDistributedCache, HybridCache and Redis, cache-aside, write-through and write-behind, cache invalidation, cache stampedes and TTL strategy.
-
How do you make cache invalidation survive a crash between the database commit and the cache delete?
Mid-Level
Theory
Caching
-
Why do we cache in a .NET service, and what are the main caching layers: in-memory, distributed and HTTP/CDN? How does IMemoryCache work, and why should you set a size limit on it?
The purpose of caching, the in-process, distributed and HTTP/CDN layers, IMemoryCache basics (expiration, eviction, GetOrCreateAsync) and why SizeLimit matters.
Junior
Theory
Caching
Β· π 3 follow-ups
-
How do IDistributedCache and Redis work in ASP.NET Core? Explain serialisation, the latency you should expect, what Redis is good at beyond key-value caching, and which Azure Redis offering you would choose today.
IDistributedCache over Redis: the byte-array API, serialisation cost, network latency, Redis data structures and features, connection management, and Azure Managed Redis versus the retiring Azure Cache for Redis.
Intermediate
Theory
Caching
Β· π 3 follow-ups
-
Show me how you would use HybridCache in .NET 10 to replace hand-written cache-aside code. Explain the two cache levels, how it protects against stampedes, how tags and invalidation work, and how you would prove the change helped.
HybridCache (Microsoft.Extensions.Caching.Hybrid, GA since March 2025): GetOrCreateAsync, L1/L2 behaviour, per-process stampede protection, tags and RemoveByTagAsync, serialisation, entry options, and measuring the improvement.
Mid-Level
Coding
Caching
Β· π 3 follow-ups Β· π 1 real-world
-
Compare cache-aside, write-through and write-behind caching. How does each keep the cache and the database consistent, what goes wrong when a step fails, and when would you choose each in a .NET service?
The three main caching write strategies (cache-aside, write-through, write-behind), their consistency guarantees, failure modes and race conditions, and where read-through fits, with .NET examples.
Mid-Level
Theory
Caching
Β· π 3 follow-ups Β· π 1 real-world
-
A hot cache key expires at peak and your database CPU hits 100%, timeouts spread across the API, and it recovers a few minutes later. You suspect a cache stampede. How do you confirm it, stop it now, and prevent it with locking, early refresh and jittered TTLs?
Diagnosing a cache stampede (thundering herd) from Application Insights, Query Store and cache metrics, and fixing it with request coalescing, HybridCache, distributed locks, probabilistic early refresh, stale-while-revalidate and TTL jitter.
Senior
Debugging
Caching
Β· π 3 follow-ups Β· π 1 real-world
-
How do you design cache invalidation and TTLs for a .NET service? Explain explicit invalidation, tag-based invalidation, versioned keys and stale-while-revalidate, and how you choose a TTL for a given piece of data.
Cache invalidation strategies (explicit delete, tags, versioned or generational keys, event-driven invalidation) and TTL design (absolute vs sliding, soft and hard expiry, stale-while-revalidate, jitter), with how to choose a TTL from business tolerance.
Mid-Level
Theory
Caching
Β· π 3 follow-ups Β· π 1 real-world
-
You run 20 instances of an ASP.NET Core service behind a load balancer. How would you design caching across them? Explain when to use a local cache, a distributed cache or both, how you keep local caches in sync with invalidation messages, and how you trade consistency against latency.
Multi-instance cache architecture: L1 per instance vs shared L2, two-level caching with HybridCache, invalidation via Redis pub/sub or Azure Service Bus, bounded staleness, failure modes, cold starts and how to choose per data class.
Senior
Architecture
Caching
Β· π 3 follow-ups Β· π 1 real-world
-
Users report seeing stale data, and one user saw another user's account details, served from your API's cache. How do you investigate, find the faulty cache key or design, contain the incident, and fix it so it can't happen again?
Investigating a cache that serves stale or cross-user data: incident containment, Privacy Act notifiable data breach assessment, finding missing key dimensions (user, tenant, culture, version), output and CDN caching of authenticated responses, and preventive design and tests.
Senior
RealWorldScenario
Caching
Β· π 3 follow-ups Β· π 1 real-world