Add HybridCache documentation to caching guide#51461
Conversation
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
docs/core/extensions/snippets/caching/hybrid-cache/csharp/HybridCacheExample.csproj
Show resolved
Hide resolved
|
@copilot please respond to feedback. |
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive documentation for HybridCache to the .NET caching guide. HybridCache is a new caching library introduced in .NET 9 that combines in-memory and distributed caching with additional features like stampede protection and tag-based invalidation.
Changes:
- Updated introduction to list HybridCache as a third caching approach alongside in-memory and distributed caching
- Added complete HybridCache section with subsections covering key features, setup, usage, configuration, tag-based invalidation, and serialization
- Created code examples demonstrating HybridCache functionality in a new snippets directory
- Added HybridCache reference link to the "See also" section
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| docs/core/extensions/caching.md | Added HybridCache section with comprehensive documentation, updated introduction to mention three caching approaches, and added reference link in "See also" |
| docs/core/extensions/snippets/caching/hybrid-cache/csharp/Program.cs | Created code snippets demonstrating HybridCache registration, configuration, basic usage, tag-based caching, invalidation, serialization, and Redis integration |
| docs/core/extensions/snippets/caching/hybrid-cache/csharp/HybridCacheExample.csproj | Created project file for code examples targeting .NET 10 with necessary package references |
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="9.0.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" /> |
There was a problem hiding this comment.
The project targets net10.0 but references version 9.0.0 packages. This creates a version mismatch. Either target net9.0 to match the package versions (9.0.0), or update the package versions to 10.0.0 if they're available for .NET 10. Since Microsoft.Extensions.Caching.Hybrid was introduced in .NET 9, and the example uses 9.0.0 packages, the target framework should be net9.0 for consistency.
|
|
||
| Register the `HybridCache` service with DI by calling <xref:Microsoft.Extensions.DependencyInjection.HybridCacheServiceExtensions.AddHybridCache%2A>: | ||
|
|
||
| :::code source="snippets/caching/hybrid-cache/csharp/Program.cs" id="BasicRegistration" highlight="2-3"::: |
There was a problem hiding this comment.
The highlight attribute specifies "2-3" but the BasicRegistration snippet only contains 2 lines (lines 7-8 in Program.cs). The highlight should be "2" to highlight only the AddHybridCache() call, or if you want to highlight both lines, it should match the actual number of lines in the snippet.
| :::code source="snippets/caching/hybrid-cache/csharp/Program.cs" id="BasicRegistration" highlight="2-3"::: | |
| :::code source="snippets/caching/hybrid-cache/csharp/Program.cs" id="BasicRegistration" highlight="2"::: |
| - <xref:Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.Expiration?displayProperty=nameWithType>: How long the entry should be cached in the distributed cache. | ||
| - <xref:Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.LocalCacheExpiration?displayProperty=nameWithType>: How long the entry should be cached in local memory. | ||
| - <xref:Microsoft.Extensions.Caching.Hybrid.HybridCacheEntryOptions.Flags?displayProperty=nameWithType>: Additional flags for controlling cache behavior. |
There was a problem hiding this comment.
These list items are sentence fragments that describe what can be configured, but they're written as incomplete sentences (e.g., "How long the entry should be cached..."). According to the Markdown writing style guidelines, list items should be complete sentences with proper punctuation. Rewrite these as complete sentences. For example: "The expiration determines how long the entry should be cached in the distributed cache." Alternatively, make them consistent descriptive phrases without periods if they're meant to be labels rather than sentences.
Plan: Update Caching Documentation with HybridCache
Summary
Successfully added comprehensive HybridCache documentation to the .NET caching guide. All feedback addressed.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews