From a391e7a5280507314e7d22ea7fe1e9b7a1569060 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Mon, 20 Jul 2020 11:07:19 +0800 Subject: [PATCH] Refactor. --- .../Volo/Abp/Caching/DistributedCache.cs | 160 +++++++++--------- .../Volo/Abp/Caching/IDistributedCache.cs | 58 +++---- .../Abp/Caching/DistributedCache_Tests.cs | 12 +- 3 files changed, 115 insertions(+), 115 deletions(-) diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs index 28082832b0..b26feec136 100644 --- a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/DistributedCache.cs @@ -53,7 +53,7 @@ namespace Volo.Abp.Caching public class DistributedCache : IDistributedCache where TCacheItem : class { - public const string DistributedCacheName = "AbpDistributedCache"; + public const string UowCacheName = "AbpDistributedCache"; public ILogger> Logger { get; set; } @@ -142,13 +142,13 @@ namespace Volo.Abp.Caching /// Gets a cache item with the given key. If no cache item is found for the given key then returns null. /// /// The key of cached item to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The cache item, or null. public virtual TCacheItem Get( TCacheKey key, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; @@ -183,8 +183,8 @@ namespace Volo.Abp.Caching public virtual KeyValuePair[] GetMany( IEnumerable keys, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { var keyArray = keys.ToArray(); @@ -193,19 +193,19 @@ namespace Volo.Abp.Caching { return GetManyFallback( keyArray, - considerUow, - hideErrors + hideErrors, + considerUow ); } - var cachedValues = new List>(); var notCachedKeys = new List(); + var cachedValues = new List>(); if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); + var uowCache = GetUnitOfWorkCache(); foreach (var key in keyArray) { - var value = cache.GetOrDefault(key)?.GetUnRemovedValueOrNull(); + var value = uowCache.GetOrDefault(key)?.GetUnRemovedValueOrNull(); if (value != null) { cachedValues.Add(new KeyValuePair(key, value)); @@ -232,7 +232,7 @@ namespace Volo.Abp.Caching if (hideErrors == true) { HandleException(ex); - return ToCacheItemsWithDefaultValues(readKeys); + return ToCacheItemsWithDefaultValues(keyArray); } throw; @@ -243,8 +243,8 @@ namespace Volo.Abp.Caching protected virtual KeyValuePair[] GetManyFallback( TCacheKey[] keys, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; @@ -253,7 +253,7 @@ namespace Volo.Abp.Caching return keys .Select(key => new KeyValuePair( key, - Get(key, considerUow, hideErrors: false) + Get(key, false, considerUow) ) ).ToArray(); } @@ -271,8 +271,8 @@ namespace Volo.Abp.Caching public virtual async Task[]> GetManyAsync( IEnumerable keys, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { var keyArray = keys.ToArray(); @@ -282,20 +282,20 @@ namespace Volo.Abp.Caching { return await GetManyFallbackAsync( keyArray, - considerUow, hideErrors, + considerUow, token ); } - var cachedValues = new List>(); var notCachedKeys = new List(); + var cachedValues = new List>(); if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); + var uowCache = GetUnitOfWorkCache(); foreach (var key in keyArray) { - var value = cache.GetOrDefault(key)?.GetUnRemovedValueOrNull(); + var value = uowCache.GetOrDefault(key)?.GetUnRemovedValueOrNull(); if (value != null) { cachedValues.Add(new KeyValuePair(key, value)); @@ -326,7 +326,7 @@ namespace Volo.Abp.Caching if (hideErrors == true) { await HandleExceptionAsync(ex); - return ToCacheItemsWithDefaultValues(readKeys); + return ToCacheItemsWithDefaultValues(keyArray); } throw; @@ -337,8 +337,8 @@ namespace Volo.Abp.Caching protected virtual async Task[]> GetManyFallbackAsync( TCacheKey[] keys, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; @@ -351,7 +351,7 @@ namespace Volo.Abp.Caching { result.Add(new KeyValuePair( key, - await GetAsync(key, considerUow, hideErrors: false, token: token)) + await GetAsync(key, false, considerUow, token: token)) ); } @@ -373,14 +373,14 @@ namespace Volo.Abp.Caching /// Gets a cache item with the given key. If no cache item is found for the given key then returns null. /// /// The key of cached item to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The for the task. /// The cache item, or null. public virtual async Task GetAsync( TCacheKey key, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; @@ -429,17 +429,17 @@ namespace Volo.Abp.Caching /// The key of cached item to be retrieved from the cache. /// The factory delegate is used to provide the cache item when no cache item is found for the given . /// The cache options for the factory delegate. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The cache item. public virtual TCacheItem GetOrAdd( TCacheKey key, Func factory, Func optionsFactory = null, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { - var value = Get(key, considerUow, hideErrors); + var value = Get(key, hideErrors, considerUow); if (value != null) { return value; @@ -447,7 +447,7 @@ namespace Volo.Abp.Caching using (SyncSemaphore.Lock()) { - value = Get(key, considerUow, hideErrors); + value = Get(key, hideErrors, considerUow); if (value != null) { return value; @@ -468,7 +468,7 @@ namespace Volo.Abp.Caching } } - Set(key, value, optionsFactory?.Invoke(), considerUow, hideErrors); + Set(key, value, optionsFactory?.Invoke(), hideErrors, considerUow); } return value; @@ -489,12 +489,12 @@ namespace Volo.Abp.Caching TCacheKey key, Func> factory, Func optionsFactory = null, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { token = CancellationTokenProvider.FallbackToProvider(token); - var value = await GetAsync(key, considerUow, hideErrors, token); + var value = await GetAsync(key, hideErrors, considerUow, token); if (value != null) { return value; @@ -502,7 +502,7 @@ namespace Volo.Abp.Caching using (await SyncSemaphore.LockAsync(token)) { - value = await GetAsync(key, considerUow, hideErrors, token); + value = await GetAsync(key, hideErrors, considerUow, token); if (value != null) { return value; @@ -523,7 +523,7 @@ namespace Volo.Abp.Caching } } - await SetAsync(key, value, optionsFactory?.Invoke(), considerUow, hideErrors, token); + await SetAsync(key, value, optionsFactory?.Invoke(), hideErrors, considerUow, token); } return value; @@ -535,14 +535,14 @@ namespace Volo.Abp.Caching /// The key of cached item to be retrieved from the cache. /// The cache item value to set in the cache. /// The cache options for the value. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. public virtual void Set( TCacheKey key, TCacheItem value, DistributedCacheEntryOptions options = null, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { void SetRealCache() { @@ -570,14 +570,14 @@ namespace Volo.Abp.Caching if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); - if (cache.TryGetValue(key, out _)) + var uowCache = GetUnitOfWorkCache(); + if (uowCache.TryGetValue(key, out _)) { - cache[key].SetValue(value); + uowCache[key].SetValue(value); } else { - cache.Add(key, new UnitOfWorkCacheItem(value)); + uowCache.Add(key, new UnitOfWorkCacheItem(value)); } // ReSharper disable once PossibleNullReferenceException @@ -598,16 +598,16 @@ namespace Volo.Abp.Caching /// The key of cached item to be retrieved from the cache. /// The cache item value to set in the cache. /// The cache options for the value. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The for the task. /// The indicating that the operation is asynchronous. public virtual async Task SetAsync( TCacheKey key, TCacheItem value, DistributedCacheEntryOptions options = null, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { async Task SetRealCache() @@ -637,14 +637,14 @@ namespace Volo.Abp.Caching if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); - if (cache.TryGetValue(key, out _)) + var uowCache = GetUnitOfWorkCache(); + if (uowCache.TryGetValue(key, out _)) { - cache[key].SetValue(value); + uowCache[key].SetValue(value); } else { - cache.Add(key, new UnitOfWorkCacheItem(value)); + uowCache.Add(key, new UnitOfWorkCacheItem(value)); } // ReSharper disable once PossibleNullReferenceException @@ -659,8 +659,8 @@ namespace Volo.Abp.Caching public void SetMany( IEnumerable> items, DistributedCacheEntryOptions options = null, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { var itemsArray = items.ToArray(); @@ -670,8 +670,8 @@ namespace Volo.Abp.Caching SetManyFallback( itemsArray, options, - considerUow, - hideErrors + hideErrors, + considerUow ); return; @@ -702,17 +702,17 @@ namespace Volo.Abp.Caching if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); + var uowCache = GetUnitOfWorkCache(); foreach (var pair in itemsArray) { - if (cache.TryGetValue(pair.Key, out _)) + if (uowCache.TryGetValue(pair.Key, out _)) { - cache[pair.Key].SetValue(pair.Value); + uowCache[pair.Key].SetValue(pair.Value); } else { - cache.Add(pair.Key, new UnitOfWorkCacheItem(pair.Value)); + uowCache.Add(pair.Key, new UnitOfWorkCacheItem(pair.Value)); } } @@ -732,8 +732,8 @@ namespace Volo.Abp.Caching protected virtual void SetManyFallback( KeyValuePair[] items, DistributedCacheEntryOptions options = null, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; @@ -745,8 +745,8 @@ namespace Volo.Abp.Caching item.Key, item.Value, options, - considerUow, - hideErrors: false + false, + considerUow ); } } @@ -765,8 +765,8 @@ namespace Volo.Abp.Caching public virtual async Task SetManyAsync( IEnumerable> items, DistributedCacheEntryOptions options = null, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { var itemsArray = items.ToArray(); @@ -777,8 +777,8 @@ namespace Volo.Abp.Caching await SetManyFallbackAsync( itemsArray, options, - considerUow, hideErrors, + considerUow, token ); @@ -811,17 +811,17 @@ namespace Volo.Abp.Caching if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); + var uowCache = GetUnitOfWorkCache(); foreach (var pair in itemsArray) { - if (cache.TryGetValue(pair.Key, out _)) + if (uowCache.TryGetValue(pair.Key, out _)) { - cache[pair.Key].SetValue(pair.Value); + uowCache[pair.Key].SetValue(pair.Value); } else { - cache.Add(pair.Key, new UnitOfWorkCacheItem(pair.Value)); + uowCache.Add(pair.Key, new UnitOfWorkCacheItem(pair.Value)); } } @@ -837,8 +837,8 @@ namespace Volo.Abp.Caching protected virtual async Task SetManyFallbackAsync( KeyValuePair[] items, DistributedCacheEntryOptions options = null, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { hideErrors = hideErrors ?? _distributedCacheOption.HideErrors; @@ -851,8 +851,8 @@ namespace Volo.Abp.Caching item.Key, item.Value, options, + false, considerUow, - hideErrors: false, token: token ); } @@ -934,8 +934,8 @@ namespace Volo.Abp.Caching /// Indicates to throw or hide the exceptions for the distributed cache. public virtual void Remove( TCacheKey key, - bool considerUow = false, - bool? hideErrors = null) + bool? hideErrors = null, + bool considerUow = false) { void RemoveRealCache() { @@ -959,10 +959,10 @@ namespace Volo.Abp.Caching if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); - if (cache.TryGetValue(key, out _)) + var uowCache = GetUnitOfWorkCache(); + if (uowCache.TryGetValue(key, out _)) { - cache[key].RemoveValue(); + uowCache[key].RemoveValue(); } // ReSharper disable once PossibleNullReferenceException @@ -982,14 +982,14 @@ namespace Volo.Abp.Caching /// Removes the cache item for given key from cache. /// /// The key of cached item to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The for the task. /// The indicating that the operation is asynchronous. public virtual async Task RemoveAsync( TCacheKey key, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default) { async Task RemoveRealCache() @@ -1014,10 +1014,10 @@ namespace Volo.Abp.Caching if (ShouldConsiderUow(considerUow)) { - var cache = GetUnitOfWorkCache(); - if (cache.TryGetValue(key, out _)) + var uowCache = GetUnitOfWorkCache(); + if (uowCache.TryGetValue(key, out _)) { - cache[key].RemoveValue(); + uowCache[key].RemoveValue(); } // ReSharper disable once PossibleNullReferenceException @@ -1104,14 +1104,14 @@ namespace Volo.Abp.Caching protected virtual string GetUnitOfWorkCacheKey() { - return DistributedCacheName + CacheName; + return UowCacheName + CacheName; } protected virtual Dictionary> GetUnitOfWorkCache() { if (UnitOfWorkManager.Current == null) { - throw new AbpException($"There is no unit of work in the current context, The {GetType().Name} can only be used in a unit of work."); + throw new AbpException($"There is no active UOW."); } return UnitOfWorkManager.Current.GetOrAddItem(GetUnitOfWorkCacheKey(), diff --git a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs index 1b0e58815e..2f74fd678b 100644 --- a/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs +++ b/framework/src/Volo.Abp.Caching/Volo/Abp/Caching/IDistributedCache.cs @@ -29,13 +29,13 @@ namespace Volo.Abp.Caching /// Gets a cache item with the given key. If no cache item is found for the given key then returns null. /// /// The key of cached item to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The cache item, or null. TCacheItem Get( TCacheKey key, - bool considerUow = false, - bool? hideErrors = null + bool? hideErrors = null, + bool considerUow = false ); /// @@ -46,13 +46,13 @@ namespace Volo.Abp.Caching /// if the related key not found in the cache. /// /// The keys of cached items to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// List of cache items. KeyValuePair[] GetMany( IEnumerable keys, - bool considerUow = false, - bool? hideErrors = null + bool? hideErrors = null, + bool considerUow = false ); /// @@ -64,14 +64,14 @@ namespace Volo.Abp.Caching /// /// /// The keys of cached items to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// /// The for the task. /// List of cache items. Task[]> GetManyAsync( IEnumerable keys, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default ); @@ -85,8 +85,8 @@ namespace Volo.Abp.Caching /// The cache item, or null. Task GetAsync( [NotNull] TCacheKey key, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default ); @@ -97,15 +97,15 @@ namespace Volo.Abp.Caching /// The key of cached item to be retrieved from the cache. /// The factory delegate is used to provide the cache item when no cache item is found for the given . /// The cache options for the factory delegate. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The cache item. TCacheItem GetOrAdd( TCacheKey key, Func factory, Func optionsFactory = null, - bool considerUow = false, - bool? hideErrors = null + bool? hideErrors = null, + bool considerUow = false ); /// @@ -115,16 +115,16 @@ namespace Volo.Abp.Caching /// The key of cached item to be retrieved from the cache. /// The factory delegate is used to provide the cache item when no cache item is found for the given . /// The cache options for the factory delegate. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The for the task. /// The cache item. Task GetOrAddAsync( [NotNull] TCacheKey key, Func> factory, Func optionsFactory = null, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default ); @@ -134,14 +134,14 @@ namespace Volo.Abp.Caching /// The key of cached item to be retrieved from the cache. /// The cache item value to set in the cache. /// The cache options for the value. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. void Set( TCacheKey key, TCacheItem value, DistributedCacheEntryOptions options = null, - bool considerUow = false, - bool? hideErrors = null + bool? hideErrors = null, + bool considerUow = false ); /// @@ -150,16 +150,16 @@ namespace Volo.Abp.Caching /// The key of cached item to be retrieved from the cache. /// The cache item value to set in the cache. /// The cache options for the value. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The for the task. /// The indicating that the operation is asynchronous. Task SetAsync( [NotNull] TCacheKey key, [NotNull] TCacheItem value, [CanBeNull] DistributedCacheEntryOptions options = null, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default ); @@ -169,13 +169,13 @@ namespace Volo.Abp.Caching /// /// Items to set on the cache /// The cache options for the value. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. void SetMany( IEnumerable> items, DistributedCacheEntryOptions options = null, - bool considerUow = false, - bool? hideErrors = null + bool? hideErrors = null, + bool considerUow = false ); /// @@ -184,15 +184,15 @@ namespace Volo.Abp.Caching /// /// Items to set on the cache /// The cache options for the value. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The for the task. /// The indicating that the operation is asynchronous. Task SetManyAsync( IEnumerable> items, DistributedCacheEntryOptions options = null, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default ); @@ -223,26 +223,26 @@ namespace Volo.Abp.Caching /// Removes the cache item for given key from cache. /// /// The key of cached item to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. void Remove( TCacheKey key, - bool considerUow = false, - bool? hideErrors = null + bool? hideErrors = null, + bool considerUow = false ); /// /// Removes the cache item for given key from cache. /// /// The key of cached item to be retrieved from the cache. - /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// Indicates to throw or hide the exceptions for the distributed cache. + /// This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache. /// The for the task. /// The indicating that the operation is asynchronous. Task RemoveAsync( TCacheKey key, - bool considerUow = false, bool? hideErrors = null, + bool considerUow = false, CancellationToken token = default ); } diff --git a/framework/test/Volo.Abp.Caching.Tests/Volo/Abp/Caching/DistributedCache_Tests.cs b/framework/test/Volo.Abp.Caching.Tests/Volo/Abp/Caching/DistributedCache_Tests.cs index 61a61ac2cd..35a72362ac 100644 --- a/framework/test/Volo.Abp.Caching.Tests/Volo/Abp/Caching/DistributedCache_Tests.cs +++ b/framework/test/Volo.Abp.Caching.Tests/Volo/Abp/Caching/DistributedCache_Tests.cs @@ -181,10 +181,10 @@ namespace Volo.Abp.Caching factoryExecuted = false; cacheItem = await personCache.GetOrAddAsync(cacheKey, - async () => + () => { factoryExecuted = true; - return new PersonCacheItem(personName); + return Task.FromResult(new PersonCacheItem(personName)); }); factoryExecuted.ShouldBeFalse(); @@ -539,7 +539,7 @@ namespace Volo.Abp.Caching cacheValue = await personCache.GetAsync(key, considerUow: false); cacheValue.ShouldBeNull(); } - + [Fact] public async Task Should_Set_And_Get_Multiple_Items_Async() { @@ -547,7 +547,7 @@ namespace Volo.Abp.Caching await personCache.SetManyAsync(new[] { - new KeyValuePair("john", new PersonCacheItem("John Nash")), + new KeyValuePair("john", new PersonCacheItem("John Nash")), new KeyValuePair("thomas", new PersonCacheItem("Thomas Moore")) }); @@ -557,7 +557,7 @@ namespace Volo.Abp.Caching "thomas", "baris" //doesn't exist }); - + cacheItems.Length.ShouldBe(3); cacheItems[0].Key.ShouldBe("john"); cacheItems[0].Value.Name.ShouldBe("John Nash"); @@ -565,7 +565,7 @@ namespace Volo.Abp.Caching cacheItems[1].Value.Name.ShouldBe("Thomas Moore"); cacheItems[2].Key.ShouldBe("baris"); cacheItems[2].Value.ShouldBeNull(); - + (await personCache.GetAsync("john")).Name.ShouldBe("John Nash"); (await personCache.GetAsync("baris")).ShouldBeNull(); }