Using named Caches with HybridCache ? #481
-
I'm attempting to utilize a named FusionCache instance within my application. However, when I try to inject it as a HybridCache, I encounter a type mismatch error: Cannot implicitly convert type 'ZiggyCreatures.Caching.Fusion.IFusionCache' to 'Microsoft.Extensions.Caching.Hybrid.HybridCache'. Is there a recommended approach to use a named FusionCache instance directly as a HybridCache, or a workaround to resolve this type incompatibility? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @seifmostafa73 , sure thing! How are you trying to do that? Can you post a code sample? If you look at the docs you can see this: Basically you can do this: services.AddFusionCache("MyNamedCache")
.AsHybridCache(); to use the cache named Hope this helps, let me know. |
Beta Was this translation helpful? Give feedback.
Hi @seifmostafa73 I'll try to make it clearer.
When you say (your code):
what you are saying is "when
HybridCache
is asked, return the FusionCache instance named"CallLogsCache"
".You don't need to specify the
FusionCache
name when asking forHybridCache
.But FusionCache can go one step further, meaning it already supports multiple named
HybridCache
instances: but since there's nothing likeIFusionCacheProvider
in the HybridCache world, the only way is via keyed services.So if you do:
you are saying is "…