With the introduction of Named Caches in v0.20.0, FusionCache internally works with the DI container to have all the registered FusionCache instances to be provided via the new IFusionCacheProvider interface.
This is all good and well, but in doing so the current implementation lost one nice feature of the DI approach, lazy instantiation.
Basically if we register in a DI container 20 components but then ask for only 5 of them, the other 15 are usually not instantiated: this saves cpu and memory.
Currently FusionCache doesn't do this, and simply instantiate all the registered ones all together.
We can do better.
Solution
Change the internal implementation to use some form of proxy class, which will be named LazyNamedCache and will be provided, during DI registration, either a FusionCache instance (in case it is directly provided during registration) or a factory.
Problem
With the introduction of Named Caches in v0.20.0, FusionCache internally works with the DI container to have all the registered FusionCache instances to be provided via the new
IFusionCacheProvider
interface.This is all good and well, but in doing so the current implementation lost one nice feature of the DI approach, lazy instantiation.
Basically if we register in a DI container 20 components but then ask for only 5 of them, the other 15 are usually not instantiated: this saves cpu and memory.
Currently FusionCache doesn't do this, and simply instantiate all the registered ones all together.
We can do better.
Solution
Change the internal implementation to use some form of proxy class, which will be named
LazyNamedCache
and will be provided, during DI registration, either aFusionCache
instance (in case it is directly provided during registration) or a factory.