/// <summary> /// Gets all. /// </summary> /// <returns>The all.</returns> /// <param name="cacheKeys">Cache keys.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public IDictionary <string, CacheValue <T> > GetAll <T>(IEnumerable <string> cacheKeys) where T : class { ArgumentCheck.NotNullAndCountGTZero(cacheKeys, nameof(cacheKeys)); var localDict = _localCachingProvider.GetAll <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 = _distributedCachingProvider.GetAll <T>(localNotFindKeys); return(localDict.Concat(disDict).ToDictionary(k => k.Key, v => v.Value)); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } return(localDict); }
protected virtual void GetAll_Should_Succeed() { _provider.RemoveAll(new List <string> { "getall:key:1", "getall:key:2" }); var dict = GetMultiDict("getall:"); _provider.SetAll(dict, _defaultTs); var res = _provider.GetAll <string>(new List <string> { "getall:key:1", "getall:key:2" }); Assert.Equal(2, res.Count); Assert.Contains("getall:key:1", res.Select(x => x.Key)); Assert.Contains("getall:key:2", res.Select(x => x.Key)); Assert.Equal("value1", res.Where(x => x.Key == "getall:key:1").Select(x => x.Value).FirstOrDefault().Value); Assert.Equal("value2", res.Where(x => x.Key == "getall:key:2").Select(x => x.Value).FirstOrDefault().Value); }