-
Notifications
You must be signed in to change notification settings - Fork 834
Support keyed HybridCache with keyed DistributedCaches and named options #6694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e3ee41e
to
7726666
Compare
I've marked this PR as a draft as we need to get [Support detect keyed dependency injected IDistributedCache as backend cache for DefaultHybridCache (#117976)](dotnet/runtime#117976) through API review, and tests would need to be added to the PR as well. I'm getting a .NET 10 RC1/RC2 bar check for this. I'll keep you posted, @ylt1534. |
3e79448
to
fe9f5e9
Compare
d4f6ecd
to
c4417a2
Compare
This comment was marked as resolved.
This comment was marked as resolved.
096297e
to
d8581f0
Compare
d3effff
to
a123285
Compare
Thanks @jeffhandley for the review. I just noticed that the DefaultHybridCache is designed as internal thus unable to DI is outside the lib. I added a new extension method and add some UTs. I want to test that the keyed instances (options, backend cache, memory cache, hybrid cache) are injected into each other correctly, but that might bring more changes like expose the _backendCache and _localCache properties from DefaultHybridCache. For now I tried to make the PR small to be easy review. thanks. |
src/Libraries/Microsoft.Extensions.Caching.Hybrid/HybridCacheServiceExtensions.cs
Outdated
Show resolved
Hide resolved
Is this going to be an issue? internal override bool IsHybridCacheActive()
=> _services.GetService<HybridCache>() is not null; this code assumes that if there is an unkeyed |
@eerhardt and I discussed the |
src/Libraries/Microsoft.Extensions.Caching.Hybrid/HybridCacheServiceExtensions.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for keyed HybridCache
instances in dependency injection, allowing multiple hybrid caches with different backing distributed caches. The main purpose is to enable scenarios where an application needs multiple hybrid caches, each potentially using separate backend caches (e.g., Redis and SQL Server).
- Introduces new
AddKeyedHybridCache
extension methods for registering keyed hybrid cache services - Adds
DistributedCacheServiceKey
property toHybridCacheOptions
to specify which keyed distributed cache to use - Updates
DefaultHybridCache
constructor to support keyed distributed cache resolution
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
HybridCacheServiceExtensions.cs | Adds new extension methods for keyed hybrid cache registration and refactors existing methods |
HybridCacheOptions.cs | Adds new property for specifying distributed cache service key |
DefaultHybridCache.cs | Updates constructor to resolve keyed distributed cache services based on options |
ServiceConstructionTests.cs | Comprehensive test coverage for new keyed hybrid cache functionality |
BasicConfig.json | Adds test configuration for distributed cache service keys |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/ServiceConstructionTests.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/ServiceConstructionTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/ServiceConstructionTests.cs
Outdated
Show resolved
Hide resolved
6f1987e
to
1402f60
Compare
It seems these ApiChief baseline JSON files, this one in particular, can match linguist's heuristic for long strings of content that cross a threshold for being identified as binary. I confirmed there's no BOM, no strange encoding or |
Closes dotnet/runtime#117976
Adds support for keyed
HybridCache
instances in DI, along with the ability to configure theDistributedCacheServiceKey
for the hybrid cache to resolve a keyedIDistributedCache
service. This opens up the scenario of having multiple hybrid caches within an application, each potentially using a separate backend cache. Those backend caches could be separate databases or entirely separate services. For example, having a Redis-backed cache alongside a SQL Server-backed cache.Microsoft Reviewers: Open in CodeFlow