Skip to content

Commit

Permalink
fix: LockMs & SleepMs not work in HybridCachingProvider.Get<T>(string…
Browse files Browse the repository at this point in the history
… cacheKey, Func<T> dataRetriever, TimeSpan expiration)
  • Loading branch information
billhong-just committed Sep 10, 2023
1 parent d088a28 commit 0402013
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions src/EasyCaching.HybridCache/HybridCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,38 +687,25 @@ public CacheValue<T> Get<T>(string cacheKey, Func<T> dataRetriever, TimeSpan exp
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
ArgumentCheck.NotNegativeOrZero(expiration, nameof(expiration));

var result = _localCache.Get<T>(cacheKey);

if (result.HasValue)
{
return result;
}

try
{
result = _distributedCache.Get<T>(cacheKey, dataRetriever, expiration);
}
catch (Exception ex)
{
LogMessage($"get with data retriever from distributed provider error [{cacheKey}]", ex);

if (_options.ThrowIfDistributedCacheError)
TimeSpan ts = GetExpiration(cacheKey);
var result = _localCache.Get(
cacheKey,
() =>
{
throw;
}
}

if (result.HasValue)
{
TimeSpan ts = GetExpiration(cacheKey);

_localCache.Set(cacheKey, result.Value, ts);

return result;
}

return CacheValue<T>.NoValue;
var value = default(T);
try
{
value = _distributedCache.Get(cacheKey, dataRetriever, expiration).Value;
}
catch (Exception ex)
{
LogMessage($"get with data retriever from distributed provider error [{cacheKey}]", ex);
if (_options.ThrowIfDistributedCacheError)
throw;
}
return value;
}, ts);
return result;
}

/// <summary>
Expand Down

0 comments on commit 0402013

Please sign in to comment.