-
-
Notifications
You must be signed in to change notification settings - Fork 254
Use auto-clone feature of the fusion cache to prevent further scale out issues when swtiching to redis (#11759) #11760
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
…ut issues when swtiching to redis (#11759)
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis pull request integrates FusionCache serialization support into the boilerplate by adding a new NuGet package dependency, configuring FusionCache with automatic cloning and a custom SystemTextJson serializer, and updating the KnownException base class from Exception to ApplicationException. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Exceptions/KnownException.cs (1)
3-3: Reconsider deriving fromApplicationExceptioninstead ofExceptionChanging
KnownExceptionto inherit fromApplicationExceptionis a behavioral change and goes against current .NET design guidance, which generally recommends deriving directly fromExceptionrather thanApplicationException. Unless you have specific handling/logging that relies onApplicationException, you may want to keepKnownException : Exceptionto avoid surprises for consumers that assume the previous hierarchy.src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs (1)
17-18: FusionCache auto-clone + SystemTextJson serializer wiring matches the PR goal, with a notable behavior changeThe new configuration
services.AddFusionCache() .WithOptions(opt => opt.DefaultEntryOptions.EnableAutoClone = true) .WithSerializer(new FusionCacheSystemTextJsonSerializer());correctly enables FusionCache’s auto‑clone feature and provides a
System.Text.Json‑basedIFusionCacheSerializer, so cached values will be cloned via serialization even when only the in‑memory layer is used—this aligns with the scale‑out/Redis objective. (docs.dndocs.com)One thing to be aware of: with
EnableAutoClone = trueas the default, any entries whose value type cannot be (de)serialized byFusionCacheSystemTextJsonSerializerwill now start throwing at runtime instead of being cached as raw objects. This may be fine if you only ever put DTOs/POCOs into FusionCache, but it’s worth double‑checking existing usages for non‑JSON‑friendly types.If you already have centralized
JsonSerializerOptions(e.g., for your APIs), consider passing them intoFusionCacheSystemTextJsonSerializerso cache serialization behavior stays consistent with the rest of your JSON stack.Also applies to: 49-52
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (4)
src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Packages.props(1 hunks)src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Boilerplate.Server.Shared.csproj(1 hunks)src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs(2 hunks)src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Exceptions/KnownException.cs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Agent
- GitHub Check: CodeQL analysis (csharp)
- GitHub Check: build Bit.Templates
🔇 Additional comments (2)
src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Packages.props (1)
135-137: FusionCache serialization package versioning looks consistentThe new
ZiggyCreatures.FusionCache.Serialization.SystemTextJsonentry at2.4.0is aligned with the other FusionCache packages (OutputCachingandOpenTelemetry), so central versioning looks coherent.Please just confirm this is the intended FusionCache version for your supported target frameworks/environments (e.g., no known regressions in 2.4.0 for
net10.0) by checking the package release notes.src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Boilerplate.Server.Shared.csproj (1)
32-35: FusionCache package references align with usage in the shared server projectAdding
ZiggyCreatures.FusionCache.AspNetCore.OutputCachingandZiggyCreatures.FusionCache.Serialization.SystemTextJsonhere matches the extension methods used inWebApplicationBuilderExtensions(AddFusionOutputCacheand the SystemTextJson serializer), and the versions are centrally managed alongside the other FusionCache packages.Please just confirm via a quick build/restore that there are no assembly binding or transitive dependency issues introduced by these additions.
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 implements the FusionCache auto-clone feature and adds JSON serialization support to prevent data mutation issues when scaling out to distributed caching (like Redis). The changes ensure that cached objects are properly cloned and serialized for safe use across multiple application instances.
- Configures FusionCache with auto-clone enabled to prevent shared reference issues
- Adds SystemTextJson serializer for proper distributed cache serialization
- Includes unrelated change to exception hierarchy base class
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Exceptions/KnownException.cs | Changes base class from Exception to ApplicationException (appears unrelated to PR purpose) |
| src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Extensions/WebApplicationBuilderExtensions.cs | Configures FusionCache with auto-clone and SystemTextJson serializer for distributed caching scenarios |
| src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Boilerplate.Server.Shared.csproj | Adds FusionCache.Serialization.SystemTextJson package reference |
| src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Packages.props | Defines version 2.4.0 for the new serialization package |
closes #11759
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.