ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.65k stars 87 forks source link

[FEATURE] 😴 Lazy named caches instantiation #152

Closed jodydonetti closed 1 year ago

jodydonetti commented 1 year ago

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 a FusionCache instance (in case it is directly provided during registration) or a factory.

jodydonetti commented 1 year ago

Hi all, v0.22.0 has been released and this is included 🎉