Closed 0xced closed 1 month ago
Hi @0xced I updated this branch based on the new main, and pushed some changes which build upon your work and can make it even better.
Basically instead of storing an IEnumerable to iterate on at every GetCache()
call, I just stored either a single LazyNamedCache
in case there was only one, or null
in case they were more than 1: in this way no need to an iteration per-call, less cpu usage and less allocations.
Finally I've made the tests a little better around these scenarios.
Thoughts?
Looks good to me too!
Storing the caches in a dictionary upfront allows to retrieve the cache in O(1) instead of O(n).
Using
Lazy<IFusionCache>
allows to preserve the semantic of throwing when accessing the (incorrectly configured) caches.Also, the
DependencyInjectionTests
were very slightly improved:GetRequiredService
instead ofGetService
plus the null-forgiving operator because anInvalidOperationException
is always better than aNullReferenceException
, even in unit tests.IFusionCache
instance is always the same no matter how it's retrieved, either throughIFusionCacheProvider
or directly by requesting theIFusionCache
.