From a4a43c2b5255081caf5327d0b235717fa03c14de Mon Sep 17 00:00:00 2001 From: Jody Donetti Date: Tue, 4 Jun 2024 15:19:35 +0200 Subject: [PATCH] Minor --- .../Internals/Provider/LazyNamedCache.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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(); + } } }