caching

Caching strategies for .NET 10 applications. Covers HybridCache (the default), output caching, response caching, and distributed cache patterns. Load this skill when implementing caching, optimizing read performance, reducing database load, or when the user mentions "cache", "HybridCache", "Redis",

By codewithmukesh · 1,182 installs

npx skills add codewithmukesh/dotnet-claude-kit --skill caching

Source repository · Upstream listing

Caching Core Principles 1. HybridCache is the default — .NET 9+ introduced HybridCache as the unified caching abstraction. It combines in memory (L1) and distributed (L2) caching with stampede protection. See ADR 004. 2. Cache reads, not writes — Cache GET operations. Invalidate on mutations. Never cache POST/PUT/DELETE responses. 3. Output caching for entire responses — When the full HTTP response can be cached (public APIs, static data), use output caching middleware. 4. Set explicit TTLs — Every cached item needs an expiration. No unbounded caches. Patterns HybridCache (Recommended Default) Cache Invalidation Output Caching (Full Response Caching) Cache Aside Pattern (Legacy) Prefer HybridCache for all new code. Manual IDistributedCache cache aside lacks stampede protection, requires manual serialization, and has no L1/L2 layering. Use only when integrating with existing code that already uses IDistributedCache directly. Anti patterns Don't Cache Without Expiration Don't Cache Mutable User Specific Data Don't Build Your Own Stampede Protection Decision Guide Scenario Recommendation General data caching HybridCache ( GetOrCreateAsync ) Full HTTP response Output caching with .CacheOutput() Frequently read, rarely written HybridCache with longer TTL User specific data HybridCache with user scoped key Cache invalidation on write cache.RemoveAsync() or output cache tags Distributed deployment HybridCache + Redis L2 backend Single server deployment HybridCache with in memory only