Improve bit Boilerplate caching configuration (#12184)#12185
Improve bit Boilerplate caching configuration (#12184)#12185yasmoradi merged 1 commit intobitfoundation:developfrom
Conversation
WalkthroughFusionCache packages are upgraded to version 2.6.0 with the addition of distributed locking support via Redis. The caching infrastructure is enhanced by enabling hybrid cache mode, introducing IDistributedCache integration with Redis or in-memory fallback, and refactoring memory cache configuration. Lambda parameter names are standardized from Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant HC as HybridCache
participant FC as FusionCache
participant MC as IMemoryCache
participant DL as RedisDistributedLocker
participant DC as IDistributedCache
participant Redis as Redis Backend
App->>HC: Register HybridCache
App->>FC: Configure FusionCache
FC->>MC: Enable L1 Cache (in-memory)
FC->>DL: Setup Distributed Locker
DL->>Redis: Connect for locking
FC->>DC: Register IDistributedCache
DC->>Redis: Use Redis backend (if available)
DC->>MC: Fallback to in-memory MemoryDistributedCache
App->>HC: Request cached data
HC->>FC: Forward to FusionCache
FC->>MC: Check L1 (memory cache)
alt Cache Hit
MC-->>FC: Return cached value
else Cache Miss
FC->>DL: Acquire distributed lock
DL->>Redis: Lock key
FC->>DC: Fetch from distributed cache
alt Redis available
DC->>Redis: Get value
Redis-->>DC: Return value
else Redis unavailable
DC->>MC: Get from in-memory fallback
MC-->>DC: Return value
end
DC-->>FC: Return value
FC->>MC: Update L1 cache
end
FC-->>HC: Return value
HC-->>App: Return to application
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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.
Pull request overview
Updates the Bit.Boilerplate template’s caching setup to better integrate FusionCache with Microsoft’s caching abstractions (HybridCache/IDistributedCache) and improve stampede protection, aligning with issue #12184.
Changes:
- Configure and register
IMemoryCachein a way that can be reused by FusionCache’s L1 cache. - Configure FusionCache as
HybridCache, add Redis distributed locking (when Redis is enabled), and registerIDistributedCachefor library compatibility. - Add a shared
GetRequiredConnectionStringhelper and update FusionCache-related package references (including the distributed locker package).
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 |
|---|---|
| src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Infrastructure/Extensions/ISharedServiceCollectionExtensions.cs | Binds MemoryCacheOptions from configuration and registers IMemoryCache separately. |
| src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs | Configures FusionCache as HybridCache, reuses registered IMemoryCache, adds Redis distributed locker, and registers IDistributedCache. |
| src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/IConfigurationExtensions.cs | Adds GetRequiredConnectionString extension to enforce required connection strings. |
| src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Boilerplate.Server.Shared.csproj | Adds package reference for FusionCache Redis distributed locking. |
| src/Templates/Boilerplate/Bit.Boilerplate/src/Directory.Packages.props | Bumps FusionCache packages to 2.6.0 and adds version for the distributed locker package. |
You can also share your feedback on Copilot code review. Take the survey.
closes #12184
Summary
Added FusionCache's adapter for Microsoft's HybridCache, so developers/libraries/middlewares would be able to inject
HybridCacheAdded Microsoft's IDistributedCache support, so developers/libraries/middlewares would be able to inject
IDistributedCacheAdded Distributed Locker for distributed stampede protection
Re-use the same
IMemoryCacheinstance for FusionCache's L1 cacheNote: Both
IMemoryCacheandMemoryDistributedCacheconfigured to not to consume the whole server's memory.