示例#1
0
        public void SetCategoryList(object category = null)
        {
            if (!_cacheManager.IsSet("CategoriList_"))
            {
                _cacheManager.Add("CategoriList_", _categoryRepository.GetMany(x => x.ParentCategoryId == 0).ToList(), 3600);
            }

            var categoryList = _cacheManager.Get <List <Category> >("CategoriList_");

            ViewBag.CategoryList = categoryList;
        }
示例#2
0
 public static T Get <T>(this IMemoryCacheManager cacheManager, string key, Func <T> acquire, int cacheTime = 60)
 {
     if (cacheManager.IsSet(key))
     {
         return(cacheManager.Get <T>(key));
     }
     else
     {
         var result = acquire();
         cacheManager.Set(key, result, cacheTime);
         return(result);
     }
 }
示例#3
0
        public async Task <T> GetItemFromHashAsync <T>(string redisKey, string redisHashKey)
        {
            var compareKey = GenerateKey(redisKey + redisHashKey);

            if (_memoryCacheManager.IsSet(compareKey))
            {
                return(_memoryCacheManager.Get <T>(compareKey));
            }

            var rValue = await _db.HashGetAsync(GenerateKey(redisKey), redisHashKey);

            if (!rValue.HasValue)
            {
                _memoryCacheManager.Set(compareKey, 0, MemoryCacheTime);
                return(default(T));
            }

            var resultValue = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(rValue);

            _memoryCacheManager.Set(compareKey, resultValue, MemoryCacheTime);

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(rValue));
        }