caching-strategies

Implements output, memory, distributed, and hybrid caching patterns for ASP.NET Core Razor Pages applications.

Updated Mar 8, 2026
One-click install
npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill caching-strategies-agibuild
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: caching-strategies
Source: https://github.com/AGIBuild/dotnet.CI.template/tree/main/.cursor/skills/caching-strategies
Command: npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill caching-strategies-agibuild

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing and correctly implementing caching in ASP.NET Core Razor Pages applications is error-prone, leading to stale data, cache stampedes, and inconsistent cache keys across a codebase. ## Core Features & Use Cases - Five Caching Patterns: Covers output caching, response caching, memory caching, Redis distributed caching, and HybridCache for .NET 9+ with complete configuration and usage code. - Cache Invalidation Strategies: Provides tag-based, event-driven, and time-based invalidation approaches with concrete C# implementations. - Anti-Pattern Guidance: Identifies cache stampede, oversized cache entries, and inconsistent key generation with corrected code examples. - Use Case: When building a multi-instance Razor Pages app, use the Redis distributed caching pattern with sliding expiration to share session data across servers while preventing stampedes via GetOrCreateAsync. ## Quick Start Ask the AI to implement caching for a Razor Pages product catalog using the appropriate pattern from this skill, such as HybridCache with tag-based invalidation.

Frequently Asked Questions about caching-strategies

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

FAQPage Schema
How do I implement caching in ASP.NET Core Razor Pages?▼

Use the [OutputCache] attribute on PageModel classes for full-page caching, or inject IMemoryCache for data-level caching. Configure policies in Program.cs with AddOutputCache and register the middleware with UseOutputCache after routing.

What is the difference between memory cache and distributed cache in ASP.NET Core?▼

Memory cache stores data in a single server instance with very low latency, while distributed cache using Redis shares data across multiple server instances. Use memory cache for single-server apps and distributed cache for load-balanced deployments.

Should I use HybridCache or IDistributedCache in .NET 9?▼

HybridCache is recommended for .NET 9+ because it combines fast local memory caching with distributed cache synchronization automatically. It also provides built-in stampede protection through GetOrCreateAsync and tag-based invalidation.

How do I prevent cache stampede in ASP.NET Core?▼

Use GetOrCreateAsync from IMemoryCache or HybridCache, which serializes concurrent cache misses so only one request hits the database. Avoid manual check-then-set patterns that allow multiple simultaneous database queries when entries expire.

How do I invalidate cached pages in Razor Pages?▼

Tag cached pages with output cache policies, then call EvictByTagAsync on IOutputCacheStore to remove all matching entries. For data caches, use RemoveAsync with specific keys or RemoveByTagAsync with HybridCache.

When should I not use output caching in ASP.NET Core?▼

Avoid output caching for pages with user-specific data unless you vary by cookie or header, and never cache error pages or sensitive authenticated content without proper variation. Use ResponseCache with NoStore for content that must never be cached.