private SemaphoreSlim GetOrCreateLock( string key, DistributedCacheEntryOptions?distributedCacheEntryOptions) { KeySemaphore.Wait(); try { return(L1Cache.GetOrCreate( $"{L1L2RedisCacheOptions.LockKeyPrefix}{key}", cacheEntry => { cacheEntry.AbsoluteExpiration = distributedCacheEntryOptions?.AbsoluteExpiration; cacheEntry.AbsoluteExpirationRelativeToNow = distributedCacheEntryOptions?.AbsoluteExpirationRelativeToNow; cacheEntry.SlidingExpiration = distributedCacheEntryOptions?.SlidingExpiration; return new SemaphoreSlim(1, 1); }) ?? new SemaphoreSlim(1, 1)); } finally { KeySemaphore.Release(); } }