caching

Guide HybridCache, output cache, and IMemoryCache usage with tag-based invalidation.

4|Updated Apr 20, 2026
One-click install
npx skills add https://github.com/zdanovichnick/dotnet-pilot --skill caching-zdanovichnick
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: caching
Source: https://github.com/zdanovichnick/dotnet-pilot/tree/main/skills/caching
Command: npx skills add https://github.com/zdanovichnick/dotnet-pilot --skill caching-zdanovichnick

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Caching in .NET often becomes inconsistent or error-prone, leading to stale data, cache stampedes, and scattered key strings that are hard to invalidate correctly.

Core Features & Use Cases

  • HybridCache for application data: Use HybridCache (.NET 9+) to combine L1 and optional L2 caching with built-in stampede protection.
  • Output caching for HTTP responses: Cache full middleware-level responses using policies and vary rules for query parameters.
  • Cache-aside and IMemoryCache support: Use cache-aside when you need manual control, or IMemoryCache for simple single-node scenarios.
  • Reliable invalidation with tags and key strategy: Invalidate single entries or groups via tags and enforce typed, tenant-scoped key factories to prevent data leakage.

Quick Start

Configure HybridCache with sensible expiration and use typed cache keys for your entity lookups, then call GetOrCreateAsync to automatically load on cache misses and stay consistent via tag-based invalidation.

Frequently Asked Questions about caching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure HybridCache in .NET 9 to prevent cache stampedes?

Configure HybridCache in .NET 9 to combine L1 and optional L2 caching, providing built-in stampede protection. Call GetOrCreateAsync to automatically load data on cache misses while maintaining consistency across single-node or multi-node scenarios.

What's the best way to invalidate grouped IMemoryCache entries in ASP.NET Core?

Invalidate grouped IMemoryCache entries by applying tag-based invalidation mechanisms. Use explicit entry removal and tags to target single entries or entire groups, ensuring cache consistency without manually tracking scattered key strings.

Does output caching in .NET support varying responses by query parameters?

Output caching in .NET supports varying full middleware-level HTTP responses by query parameters. Apply specific output cache policies with vary rules to cache endpoint responses efficiently and avoid duplicated HTTP processing.

How do I implement a typed, tenant-scoped cache key strategy for .NET applications?

Implement a typed, tenant-scoped cache key strategy by enforcing typed cache key factories for entity lookups. This structured key strategy prevents cross-tenant data leakage and ensures cache entries are safely isolated and predictable.

When should I use cache-aside versus HybridCache for application data retrieval?

Use cache-aside when you need manual control over application data retrieval, or HybridCache for automated L1/L2 integration with stampede protection. Choose IMemoryCache specifically for simple single-node in-process caching scenarios.

Why does my .NET distributed cache return stale data after database updates?

Distributed caching returns stale data when invalidation is unstructured. Use explicit invalidation mechanisms with tag-based entry removal and typed key strategies to immediately clear outdated application data and maintain database consistency.