-
Notifications
You must be signed in to change notification settings - Fork 183
[FEATURE] Make setting up NullFusionCache easier in ASP.NET #440
Copy link
Copy link
Closed
Description
Problem
Configuring FusionCache in a test scenario isn't as straight forward at it could be :)
I found NullFusionCache via issues and discussions.
I then had to guess how I should use/configure it.
Solution
Add some docs in docs/Testing.md 😄 (or similar)
So it's easier to find and figure out the best way to configure it.
Alternatives
Could also consider making an extension helper
builder.Services.AddNullFusionCache();or something like that
Additional context
Be mindful of the AsHybridCache. It doesn't inject IFusionCache
| return new FusionHybridCache(builder.Build(sp)); |
So replacing IFusionCache with the NullFusionCache doesn't work when using AsHybridCache as it'll still use whatever cache was configured first.
That means that this won't work
services.Replace(
ServiceDescriptor.Singleton<IFusionCache>(_ => new NullFusionCache(new FusionCacheOptions()))
);I had to do this:
services.Replace(
ServiceDescriptor.Singleton<IFusionCache>(_ => new NullFusionCache(new FusionCacheOptions()))
);
services.Replace(
ServiceDescriptor.Singleton<HybridCache>(sp => new FusionHybridCache(
sp.GetRequiredService<IFusionCache>()
))
);Perhaps AsHybridCache can be changed to
return new FusionHybridCache(sp.GetRequiredService<IFusionCache>());Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request