|
|
@ -3,6 +3,8 @@ using System.Linq; |
|
|
using System.Threading; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Microsoft.Extensions.Caching.Distributed; |
|
|
using Microsoft.Extensions.Caching.Distributed; |
|
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions; |
|
|
using Microsoft.Extensions.Options; |
|
|
using Microsoft.Extensions.Options; |
|
|
using Nito.AsyncEx; |
|
|
using Nito.AsyncEx; |
|
|
using Volo.Abp.MultiTenancy; |
|
|
using Volo.Abp.MultiTenancy; |
|
|
@ -14,6 +16,8 @@ namespace Volo.Abp.Caching |
|
|
public class DistributedCache<TCacheItem> : IDistributedCache<TCacheItem> |
|
|
public class DistributedCache<TCacheItem> : IDistributedCache<TCacheItem> |
|
|
where TCacheItem : class |
|
|
where TCacheItem : class |
|
|
{ |
|
|
{ |
|
|
|
|
|
public ILogger<DistributedCache<TCacheItem>> Logger { get; set; } |
|
|
|
|
|
|
|
|
protected string CacheName { get; set; } |
|
|
protected string CacheName { get; set; } |
|
|
|
|
|
|
|
|
protected bool IgnoreMultiTenancy { get; set; } |
|
|
protected bool IgnoreMultiTenancy { get; set; } |
|
|
@ -39,6 +43,7 @@ namespace Volo.Abp.Caching |
|
|
IOptions<DistributedCacheOptions> distributedCacheOption, |
|
|
IOptions<DistributedCacheOptions> distributedCacheOption, |
|
|
IDistributedCache cache, |
|
|
IDistributedCache cache, |
|
|
ICancellationTokenProvider cancellationTokenProvider, |
|
|
ICancellationTokenProvider cancellationTokenProvider, |
|
|
|
|
|
|
|
|
IObjectSerializer objectSerializer, |
|
|
IObjectSerializer objectSerializer, |
|
|
ICurrentTenant currentTenant) |
|
|
ICurrentTenant currentTenant) |
|
|
{ |
|
|
{ |
|
|
@ -46,6 +51,7 @@ namespace Volo.Abp.Caching |
|
|
_cacheOption = cacheOption.Value; |
|
|
_cacheOption = cacheOption.Value; |
|
|
Cache = cache; |
|
|
Cache = cache; |
|
|
CancellationTokenProvider = cancellationTokenProvider; |
|
|
CancellationTokenProvider = cancellationTokenProvider; |
|
|
|
|
|
Logger = NullLogger<DistributedCache<TCacheItem>>.Instance; |
|
|
ObjectSerializer = objectSerializer; |
|
|
ObjectSerializer = objectSerializer; |
|
|
CurrentTenant = currentTenant; |
|
|
CurrentTenant = currentTenant; |
|
|
|
|
|
|
|
|
@ -62,10 +68,11 @@ namespace Volo.Abp.Caching |
|
|
{ |
|
|
{ |
|
|
cachedBytes = Cache.Get(NormalizeKey(key)); |
|
|
cachedBytes = Cache.Get(NormalizeKey(key)); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if ((bool) hideErrors) |
|
|
if ((bool) hideErrors) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
throw; |
|
|
throw; |
|
|
@ -89,10 +96,11 @@ namespace Volo.Abp.Caching |
|
|
{ |
|
|
{ |
|
|
cachedBytes = await Cache.GetAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); |
|
|
cachedBytes = await Cache.GetAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if ((bool)hideErrors) |
|
|
if ((bool)hideErrors) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
throw; |
|
|
throw; |
|
|
@ -174,12 +182,15 @@ namespace Volo.Abp.Caching |
|
|
options ?? DefaultCacheOptions |
|
|
options ?? DefaultCacheOptions |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if (!(bool) hideErrors) |
|
|
if ((bool) hideErrors) |
|
|
{ |
|
|
{ |
|
|
throw; |
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -196,10 +207,11 @@ namespace Volo.Abp.Caching |
|
|
CancellationTokenProvider.FallbackToProvider(token) |
|
|
CancellationTokenProvider.FallbackToProvider(token) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if ((bool)hideErrors) |
|
|
if ((bool)hideErrors) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
return Task.CompletedTask; |
|
|
return Task.CompletedTask; |
|
|
} |
|
|
} |
|
|
throw; |
|
|
throw; |
|
|
@ -214,12 +226,15 @@ namespace Volo.Abp.Caching |
|
|
{ |
|
|
{ |
|
|
Cache.Refresh(NormalizeKey(key)); |
|
|
Cache.Refresh(NormalizeKey(key)); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if (!(bool) hideErrors) |
|
|
if ((bool) hideErrors) |
|
|
{ |
|
|
{ |
|
|
throw; |
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -231,10 +246,11 @@ namespace Volo.Abp.Caching |
|
|
{ |
|
|
{ |
|
|
return Cache.RefreshAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); |
|
|
return Cache.RefreshAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if ((bool)hideErrors) |
|
|
if ((bool)hideErrors) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
return Task.CompletedTask; |
|
|
return Task.CompletedTask; |
|
|
} |
|
|
} |
|
|
throw; |
|
|
throw; |
|
|
@ -249,12 +265,14 @@ namespace Volo.Abp.Caching |
|
|
{ |
|
|
{ |
|
|
Cache.Remove(NormalizeKey(key)); |
|
|
Cache.Remove(NormalizeKey(key)); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if (!(bool)hideErrors) |
|
|
if ((bool) hideErrors) |
|
|
{ |
|
|
{ |
|
|
throw; |
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -266,10 +284,11 @@ namespace Volo.Abp.Caching |
|
|
{ |
|
|
{ |
|
|
return Cache.RemoveAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); |
|
|
return Cache.RemoveAsync(NormalizeKey(key), CancellationTokenProvider.FallbackToProvider(token)); |
|
|
} |
|
|
} |
|
|
catch (Exception) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
if ((bool)hideErrors) |
|
|
if ((bool)hideErrors) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Logger.LogException(ex, LogLevel.Warning); |
|
|
return Task.CompletedTask; |
|
|
return Task.CompletedTask; |
|
|
} |
|
|
} |
|
|
throw; |
|
|
throw; |
|
|
|