Hybrid Cache add DisableLocalCacheSerialization - Partially fixes #6063#7641
Open
snakex64 wants to merge 3 commits into
Open
Hybrid Cache add DisableLocalCacheSerialization - Partially fixes #6063#7641snakex64 wants to merge 3 commits into
snakex64 wants to merge 3 commits into
Conversation
Add DisableLocalCacheSerialization to hybrid cache. Partially fixes dotnet#6063 Enables the hybrid cache to skip serialization when fetching from L1 (in memory) cache. This speeds up the cache when possible, and allows getting the same object instance. ```
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new opt-in HybridCacheOptions.DisableLocalCacheSerialization switch to allow the HybridCache L1 (in-memory) layer to return cached values by reference (avoiding the defensive-copy deserialize path), which can improve performance and enables caching scenarios where deserialization into the declared type is not possible (e.g., interfaces).
Changes:
- Introduces
HybridCacheOptions.DisableLocalCacheSerializationas a public option (API baseline updated). - Wires the option into
DefaultHybridCacheby changing the cache-item type selection to store mutable values as “immutable” (by-reference) cache items when enabled. - Adds tests validating reference equality behavior for mutable values when L1 hits occur.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/L2Tests.cs | Adds coverage for by-reference L1 behavior when local serialization is disabled. |
| test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/BufferReleaseTests.cs | Updates CacheItem<T>.Create call sites for the new signature. |
| src/Libraries/Microsoft.Extensions.Caching.Hybrid/Microsoft.Extensions.Caching.Hybrid.json | Adds the new public option to the API baseline. |
| src/Libraries/Microsoft.Extensions.Caching.Hybrid/Internal/DefaultHybridCache.StampedeStateT.cs | Passes the new option into cache-item creation. |
| src/Libraries/Microsoft.Extensions.Caching.Hybrid/Internal/DefaultHybridCache.CacheItem.cs | Extends CacheItem<T>.Create to allow forcing immutable/by-reference cache items. |
| src/Libraries/Microsoft.Extensions.Caching.Hybrid/HybridCacheOptions.cs | Documents the new option on HybridCacheOptions. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This add a
DisableLocalCacheSerializationoption to hybrid cache. Partially fixes #6063It enables the hybrid cache to skip serialization when storing or fetching from L1 (in memory) cache. This speeds up the cache when possible, and allows getting the same object instance.
It "partially" fixes the issue because I realized after I started that I couldn't add a flag in here:
HybridCacheEntryFlags.cs since it's in another repo.
I wanted to get the conversation going again before I spend more time on it, but the better choice in my opinion would be to add a flag for each entry instead of globally like I did in this PR. But thisrequires doing a PR in the runtime repo too.
If this implementation seems good conceptually I will just need guidance into how to create and synchronize the 2 PR required to change both the "extensions" and the "runtime" repo :)
Microsoft Reviewers: Open in CodeFlow