Exemple #1
0
        /// <summary>
        /// 读取缓存
        /// </summary>
        /// <param name="arguments">拦截方法的参数</param>
        /// <param name="returnType">拦截方法的返回类型</param>
        /// <returns></returns>
        public object LoadIntercept(object[] arguments, Type returnType)
        {
            var rightKey = _keyGenerator.GetRightKey(arguments);
            var leftKey  = _keyGenerator.GetKeyRegion(KeyNamespace,
                                                      string.IsNullOrEmpty(KeyPerfix) ? returnType.Name : KeyPerfix);
            var cacheKey = _keyGenerator.GetCacheKey(leftKey, rightKey);
            var cache    = CacheRepo.StringGet(cacheKey, returnType);

            return(cache);
        }
Exemple #2
0
        /// <summary>
        /// 读取缓存
        /// </summary>
        /// <param name="arguments">拦截方法的参数</param>
        /// <param name="returnType">拦截方法的返回类型</param>
        /// <returns></returns>
        public object LoadIntercept(object[] arguments, Type returnType)
        {
            var filedKey  = _keyGenerator.GetRightKey(arguments, FieldIndex);
            var regionKey = _keyGenerator.GetKeyRegion(KeyNamespace, string.IsNullOrEmpty(KeyPerfix) ? returnType.Name : KeyPerfix);
            var itemKey   = KeyIndex != null && KeyIndex.Length > 0 ? _keyGenerator.GetRightKey(arguments, KeyIndex) : "";
            var cacheKey  = _keyGenerator.GetCacheKey(regionKey, itemKey);
            var cache     = CacheRepo.HashGet(cacheKey, filedKey, returnType);

            return(cache);
        }
        /// <summary>
        /// 更新缓存
        /// </summary>
        /// <param name="arguments">拦截方法的参数</param>
        /// <param name="returnValue">拦截方法的返回值</param>
        /// <param name="returnType">拦截方法的返回类型</param>
        public void UpdateIntercept(object[] arguments, Type returnType, object returnValue)
        {
            var leftKey = _keyGenerator.GetKeyRegion(KeyNamespace,
                                                     string.IsNullOrEmpty(KeyPerfix) ? returnType.Name : KeyPerfix);
            var rightKey = _keyGenerator.GetRightKey(arguments, ItemArgsIndex);
            var cacheKey = _keyGenerator.GetCacheKey(leftKey, rightKey);

            CacheRepo.StringSet(cacheKey, returnValue, returnType, Expires);
        }
Exemple #4
0
        /// <summary>
        /// 更新缓存
        /// </summary>
        /// <param name="arguments">拦截方法的参数</param>
        /// <param name="returnValue">拦截方法的返回值</param>
        /// <param name="returnType">拦截方法的返回类型</param>
        public void UpdateIntercept(object[] arguments, Type returnType, object returnValue)
        {
            var regionKey = _keyGenerator.GetKeyRegion(KeyNamespace, string.IsNullOrEmpty(KeyPerfix) ? returnType.Name : KeyPerfix);
            var itemKey   = KeyIndex != null && KeyIndex.Length > 0 ? _keyGenerator.GetRightKey(arguments, KeyIndex) : "";
            var fieldKey  = _keyGenerator.GetRightKey(arguments, FieldIndex);
            var cacheKey  = _keyGenerator.GetCacheKey(regionKey, itemKey);

            CacheRepo.HashSet(cacheKey, fieldKey, returnValue, returnType, Expires);
        }
 /// <summary>
 /// 移除缓存
 /// </summary>
 /// <param name="arguments">拦截方法的参数</param>
 /// <param name="returnType">拦截方法的返回类型</param>
 /// <param name="returnValue">拦截方法的返回值</param>
 public void RemoveIntercept(object[] arguments, Type returnType, object returnValue)
 {
     foreach (var keyPerfix in KeysPerfix)
     {
         var regionKey = _keyGenerator.GetKeyRegion(KeyNamespace,
                                                    string.IsNullOrEmpty(keyPerfix) ? returnType.Name : keyPerfix);
         var itemKeys = new List <string>();
         if (KeyIndex != null && KeyIndex.Length > 0)
         {
             itemKeys.Add(_keyGenerator.GetRightKey(arguments, KeyIndex));
             foreach (var key in KeyIndex)
             {
                 itemKeys.Add(_keyGenerator.GetRightKey(arguments, key));
             }
         }
         var fieldKeys = new List <string>();
         if (FieldIndex != null && FieldIndex.Length > 0)
         {
             fieldKeys.Add(_keyGenerator.GetRightKey(arguments, FieldIndex));
             foreach (var field in FieldIndex)
             {
                 fieldKeys.Add(_keyGenerator.GetRightKey(arguments, field));
             }
         }
         var cacheKeys = new List <string>();
         if (itemKeys.Count > 0)
         {
             foreach (var itemKey in itemKeys)
             {
                 cacheKeys.Add(_keyGenerator.GetCacheKey(regionKey, itemKey));
             }
         }
         else
         {
             cacheKeys.Add(regionKey);
         }
         cacheKeys = cacheKeys.Distinct().ToList();
         if (cacheKeys.Count > 0)
         {
             foreach (var cacheKey in cacheKeys)
             {
                 if (fieldKeys.Count > 0)
                 {
                     foreach (var filedKey in fieldKeys)
                     {
                         CacheRepo.HashDelete(cacheKey, filedKey);
                     }
                 }
                 else
                 {
                     CacheRepo.KeyDelete(cacheKey);
                 }
             }
         }
     }
 }
        /// <summary>
        /// 移除缓存
        /// </summary>
        /// <param name="arguments">拦截方法的参数</param>
        /// <param name="returnType">拦截方法的返回类型</param>
        /// <param name="returnValue">拦截方法的返回值</param>
        public void RemoveIntercept(object[] arguments, Type returnType, object returnValue)
        {
            foreach (var keyPerfix in KeysPerfix)
            {
                var leftKey = _keyGenerator.GetKeyRegion(KeyNamespace,
                                                         string.IsNullOrEmpty(keyPerfix) ? returnType.Name : keyPerfix);

                var rightKeys = new List <string>();
                if (FieldIndex != null && FieldIndex.Length > 0)
                {
                    rightKeys.Add(_keyGenerator.GetRightKey(arguments, FieldIndex));
                    foreach (var field in FieldIndex)
                    {
                        rightKeys.Add(_keyGenerator.GetRightKey(arguments, field));
                    }
                }
                var cacheKeys = new List <string>();
                if (rightKeys.Count > 0)
                {
                    foreach (var rightKey in rightKeys)
                    {
                        cacheKeys.Add(_keyGenerator.GetCacheKey(leftKey, rightKey));
                    }
                    cacheKeys = cacheKeys.Distinct().ToList();
                    if (cacheKeys.Count > 0)
                    {
                        foreach (var cacheKey in cacheKeys)
                        {
                            CacheRepo.KeyDelete(cacheKey);
                        }
                    }
                }
                else
                {
                    cacheKeys.Add(leftKey + ":*");
                    cacheKeys = cacheKeys.Distinct().ToList();
                    if (cacheKeys.Count > 0)
                    {
                        foreach (var cacheKey in cacheKeys)
                        {
                            CacheRepo.KeyDeletePattern(cacheKey);
                        }
                    }
                }
            }
        }