diff --git a/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs b/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs index a43011c82b..e430a04d5e 100644 --- a/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs +++ b/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs @@ -24,9 +24,18 @@ namespace Volo.Abp.Caching ObjectSerializer = objectSerializer; } - public async Task GetAsync( - string key, - CancellationToken token = default) + public TCacheItem Get(string key) + { + var cachedBytes = Cache.Get(key); + if (cachedBytes == null) + { + return null; + } + + return ObjectSerializer.Deserialize(cachedBytes); + } + + public async Task GetAsync(string key, CancellationToken token = default) { var cachedBytes = await Cache.GetAsync(key, CancellationTokenProvider.FallbackToProvider(token)); if (cachedBytes == null) @@ -37,11 +46,16 @@ namespace Volo.Abp.Caching return ObjectSerializer.Deserialize(cachedBytes); } - public Task SetAsync( - string key, - TCacheItem value, - DistributedCacheEntryOptions options = null, - CancellationToken token = default) + public void Set(string key, TCacheItem value, DistributedCacheEntryOptions options) + { + Cache.Set( + key, + ObjectSerializer.Serialize(value), + options ?? new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(20) } //TODO: implement per cache item and global defaults!!! + ); + } + + public Task SetAsync(string key, TCacheItem value, DistributedCacheEntryOptions options = null, CancellationToken token = default) { return Cache.SetAsync( key, @@ -51,9 +65,22 @@ namespace Volo.Abp.Caching ); } - public Task RemoveAsync( - string key, - CancellationToken token = default) + public void Refresh(string key) + { + Cache.Refresh(key); + } + + public Task RefreshAsync(string key, CancellationToken token = default) + { + return Cache.RefreshAsync(key, CancellationTokenProvider.FallbackToProvider(token)); + } + + public void Remove(string key) + { + Cache.Remove(key); + } + + public Task RemoveAsync(string key, CancellationToken token = default) { return Cache.RemoveAsync(key, CancellationTokenProvider.FallbackToProvider(token)); } diff --git a/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs b/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs index e6da33bf67..686e76e6fc 100644 --- a/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs +++ b/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs @@ -8,11 +8,21 @@ namespace Volo.Abp.Caching public interface IDistributedCache where TCacheItem : class { + TCacheItem Get( + string key + ); + Task GetAsync( [NotNull] string key, CancellationToken token = default ); + void Set( + string key, + TCacheItem value, + DistributedCacheEntryOptions options + ); + Task SetAsync( [NotNull] string key, [NotNull] TCacheItem value, @@ -20,6 +30,19 @@ namespace Volo.Abp.Caching CancellationToken token = default ); + void Refresh( + string key + ); + + Task RefreshAsync( + string key, + CancellationToken token = default + ); + + void Remove( + string key + ); + Task RemoveAsync( string key, CancellationToken token = default