-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Hybrid cache: Check for ContentCacheNode instead of object on exists for hybrid cache to ensure correct deserialization (closes #20352)
#20383
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
…ache to ensure correct deserialization.
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 fixes a hybrid cache deserialization issue where the ExistsAsync method was checking for generic object types instead of the specific ContentCacheNode type, causing failures with L2 caches that require proper serialization (like SQL Server or Redis).
Key Changes
- Made
ExistsAsyncextension method generic to use proper type checking - Updated all callers to specify
ContentCacheNodeas the type parameter - Added proper test coverage with
ContentCacheNodeobjects instead of strings
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Umbraco.PublishedCache.HybridCache/Extensions/HybridCacheExtensions.cs | Made ExistsAsync method generic to accept type parameter |
| src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs | Updated ExistsAsync calls to specify ContentCacheNode type |
| src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs | Updated ExistsAsync calls to specify ContentCacheNode type |
| tests/Umbraco.Tests.UnitTests/Umbraco.PublishedCache.HybridCache/Extensions/HybridCacheExtensionsTests.cs | Updated tests to use ContentCacheNode objects and proper generic method calls |
ContentCacheNode instead of object on exists for hybrid cache to ensure correct deserialization (closes #20352)
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.
Looks good, works great 🚀
|
This pull request has been mentioned on Umbraco community forum. There might be relevant details there: https://forum.umbraco.com/t/hybrid-cache-defaultjsonserializer-error/5889/8 |
Prerequisites
Fixes #20352 caused by a regression introduced by #19890.
Description
Although the reported issue related to Redis, this is visible with any L2 cache other than a memory cache where deserialization is required.
The problem comes about because we are using
objectto verify the existence of something in the cache, rather than the actual objectContentCacheNodewe always store, which has configured serialization rules. As such the deserialization is using the default JSON serializer, which fails as we aren't stored cached values as JSON.Testing
Set up SQL L2 cache, which if running from source, is done by:
Directory.Packages.props:Umbraco.Web.UI.csproj:Program.cs, just beforeWebApplication app = builder.Build();:appSettings.json:Now verify the issue resolution with:
main. The first time it'll be fine, as the table is empty and will be populated.select * from TestCachetruncate table TestCache