Removes usages of UpgradeableReadLock

This commit is contained in:
Shannon
2021-04-20 18:02:23 +10:00
parent bf7a3251d8
commit dc08997040
5 changed files with 43 additions and 43 deletions

View File

@@ -110,19 +110,34 @@ namespace Umbraco.Core.Cache
Lazy<object> result;
using (var lck = new UpgradeableReadLock(_locker))
try
{
_locker.EnterUpgradeableReadLock();
result = MemoryCache.Get(key) as Lazy<object>;
if (result == null || FastDictionaryAppCacheBase.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null
{
result = FastDictionaryAppCacheBase.GetSafeLazy(factory);
var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles);
lck.UpgradeToWriteLock();
//NOTE: This does an add or update
MemoryCache.Set(key, result, policy);
try
{
_locker.EnterWriteLock();
//NOTE: This does an add or update
MemoryCache.Set(key, result, policy);
}
finally
{
if (_locker.IsWriteLockHeld)
_locker.ExitWriteLock();
}
}
}
finally
{
if (_locker.IsUpgradeableReadLockHeld)
_locker.ExitUpgradeableReadLock();
}
//return result.Value;