diff --git a/src/ZiggyCreatures.FusionCache/Internals/Provider/LazyNamedCache.cs b/src/ZiggyCreatures.FusionCache/Internals/Provider/LazyNamedCache.cs index 82f98a6c..bab0e137 100644 --- a/src/ZiggyCreatures.FusionCache/Internals/Provider/LazyNamedCache.cs +++ b/src/ZiggyCreatures.FusionCache/Internals/Provider/LazyNamedCache.cs @@ -48,15 +48,16 @@ public IFusionCache Cache if (_cache is not null) return _cache; - if (_cacheFactory is not null) + lock (_mutex) { - lock (_mutex) - { - return _cache = _cacheFactory(); - } - } + if (_cache is not null) + return _cache; + + if (_cacheFactory is null) + throw new InvalidOperationException("No cache and no cache factory specified: this should not be possible."); - throw new InvalidOperationException("This should not be possible"); + return _cache = _cacheFactory(); + } } }