Ejemplo n.º 1
0
        /// <summary>
        /// Gets all async.
        /// </summary>
        /// <returns>The all async.</returns>
        /// <param name="cacheKeys">Cache keys.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async Task <IDictionary <string, CacheValue <T> > > GetAllAsync <T>(IEnumerable <string> cacheKeys) where T : class
        {
            ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys));

            var localDict = await _localCachingProvider.GetAllAsync <T>(cacheKeys);

            //not find in local caching.
            var localNotFindKeys = localDict.Where(x => !x.Value.HasValue).Select(x => x.Key);

            if (localNotFindKeys.Count() <= 0)
            {
                return(localDict);
            }

            try
            {
                foreach (var item in localNotFindKeys)
                {
                    localDict.Remove(item);
                }

                var disDict = await _distributedCachingProvider.GetAllAsync <T>(cacheKeys);

                return(localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value));
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            return(localDict);
        }
Ejemplo n.º 2
0
        protected virtual async Task GetAllAsync_Should_Succeed()
        {
            _provider.RemoveAll(new List <string> {
                "getallasync:key:1", "getallasync:key:2"
            });
            var dict = GetMultiDict("getallasync:");

            _provider.SetAll(dict, _defaultTs);

            var res = await _provider.GetAllAsync <string>(new List <string> {
                "getallasync:key:1", "getallasync:key:2"
            });

            Assert.Equal(2, res.Count);

            Assert.Contains("getallasync:key:1", res.Select(x => x.Key));
            Assert.Contains("getallasync:key:2", res.Select(x => x.Key));
            Assert.Equal("value1", res.Where(x => x.Key == "getallasync:key:1").Select(x => x.Value).FirstOrDefault().Value);
            Assert.Equal("value2", res.Where(x => x.Key == "getallasync:key:2").Select(x => x.Value).FirstOrDefault().Value);
        }