Production engineering
Reveal answer and reasoning
A cache stampede occurs when concurrent misses cause repeated source work for the same entry. The relevant owner in this lesson is one real HybridCache instance, not every process that happens to use an equal key. Its shared operation can serve several waiting callers while one factory produces the value. Program.cs registers the actual Microsoft.Extensions.Caching.Hybrid package at version 10.11.0, separately from the ASP.NET and SQLite versions.
No secondary cache is configured. Begin by naming the cache instance, key and factory lifetime so that one successful demonstration is not silently expanded into distributed coordination or general consistency across unrelated entries.
The real /cache/shared endpoint calls GetOrCreateAsync with the fixed stampede:demo key. CacheProbe.Create increments its factory counter, captures the current gate task under a lock and awaits that task with the token supplied by HybridCache. Closing the development gate keeps the factory outstanding while up to eight owned HTTP callers join it. Opening the gate lets the value containing generation one complete. /cache/stats exposes the factory count separately from the returned value.
Use a fresh fixture when expecting generation one because resetting an entry removes cached data without resetting the cumulative CacheProbe counters or recreating the cache service.
What a strong answer covers
- A cache stampede occurs when concurrent misses cause repeated source work for the same entry.
- The real /cache/shared endpoint calls GetOrCreateAsync with the fixed stampede:demo key.
- The package documents that factory cancellation reflects all callers abandoning the shared operation; canceling one waiter is a different event from canceling every participant.
Common pitfall
The package documents that factory cancellation reflects all callers abandoning the shared operation; canceling one waiter is a different event from canceling every participant. Distinct keys can legitimately start distinct factories. Other HybridCache instances, including instances in another process, do not inherit this owner's coordination even if a secondary store were shared. Neither a one-minute expiration nor RemoveAsync makes source data and cached data one transaction. The sample's ordinary Task companion is even narrower: it assumes serialized access and never retries a failed or canceled pending task. Keep each limitation attached to the component that actually owns it.
Follow-up questions
- How would a stream of unique cache keys defeat same-key coalescing, and where would you place a separate source-work budget?
- Why can a later clean cache reset produce generation2 without proving that the previous miss ran two factories?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.