Esempio n. 1
0
        /// <summary>
        /// Gets the by prefix async.
        /// </summary>
        /// <returns>The by prefix async.</returns>
        /// <param name="prefix">Prefix.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public async Task <IDictionary <string, CacheValue <T> > > GetByPrefixAsync <T>(string prefix) where T : class
        {
            ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));

            var localDict = await _localCachingProvider.GetByPrefixAsync <T>(prefix);

            //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.GetByPrefixAsync <T>(prefix);

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

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

            _provider.SetAll(dict, _defaultTs);

            string prefix = "getbyprefixasync:key:";

            var res = await _provider.GetByPrefixAsync <string>(prefix);

            Assert.Equal(2, res.Count);
            Assert.Contains("getbyprefixasync:key:1", res.Select(x => x.Key));
            Assert.Contains("getbyprefixasync:key:2", res.Select(x => x.Key));
            Assert.Equal("value1", res.Where(x => x.Key == "getbyprefixasync:key:1").Select(x => x.Value).FirstOrDefault().Value);
            Assert.Equal("value2", res.Where(x => x.Key == "getbyprefixasync:key:2").Select(x => x.Value).FirstOrDefault().Value);
        }
Esempio n. 3
0
        public override async Task <Order> Get(string key)
        {
            // LIMIT TO ONE
            var cached = await _cachingProvider.GetByPrefixAsync <Order>(key);

            Console.WriteLine("point -2");
            if (cached.Count == 0)
            {
                return(null);
            }
            Console.WriteLine("point -1");
            return(cached.Values.First().Value);
        }
Esempio n. 4
0
 public async Task <IDictionary <string, CacheValue <T> > > GetAllByPrefixAsync <T>(string prefix = "")
 {
     return(await _provider.GetByPrefixAsync <T>(prefix));
 }
Esempio n. 5
0
        /// <summary>
        /// Gets the by prefix async.
        /// </summary>
        /// <typeparam name="T">Type of cache value</typeparam>
        /// <param name="prefix">Prefix of CacheKey.</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns>Dictionary of key/value cache items</returns>
        public async Task <Dictionary <string, T> > GetByPrefixAsync <T>(string prefix, CancellationToken cancellationToken = default)
        {
            var items = await _easyCachingProvider.GetByPrefixAsync <T>(prefix).ConfigureAwait(false);

            return(items.ToDictionary(p => p.Key, p => p.Value.Value));
        }