public static string Generate(MemoryCacheKey key, string identifier = "")
 {
     if (string.IsNullOrEmpty(identifier))
     {
         return(key.ToString());
     }
     return($"{key.ToString()}_{identifier}");
 }
Пример #2
0
        public void Remove(MemoryCacheKey key, object addKey)
        {
            string str_addKey = addKey == null ? "" : addKey.ToString();
            string allKey     = key.ToString() + (!string.IsNullOrEmpty(str_addKey) ? "-" + str_addKey : "");

            this.Remove(allKey);
        }
Пример #3
0
        public bool IsSet(MemoryCacheKey key, object addKey)
        {
            string str_addKey = addKey == null ? "" : addKey.ToString();
            string allKey     = key.ToString() + (!string.IsNullOrEmpty(str_addKey) ? "-" + str_addKey : "");

            return(Cache.Contains(allKey));
        }
Пример #4
0
        public void RemoveStartWith(MemoryCacheKey key)
        {
            string _key = key.ToString();
            var    list = this.CacheList().Where(x => x.StartsWith(_key)).ToList();

            foreach (var item in list)
            {
                this.Remove(item);
            }
        }
Пример #5
0
        private T Get <T>(MemoryCacheKey cacheKey, object addKey, int cacheTime, Func <T> acquire)
        {
            string str_addKey = addKey == null ? "" : addKey.ToString();
            string key        = cacheKey.ToString() + (!string.IsNullOrEmpty(str_addKey) ? "-" + str_addKey : "");

            lock (_syncObject)
            {
                if (this.IsSet(cacheKey, addKey))
                {
                    return(this.Get <T>(key));
                }

                var result = acquire();
                if (cacheTime > 0)
                {
                    this.Set(key, result, cacheTime);
                }
                return(result);
            }
        }
Пример #6
0
 public void Remove(MemoryCacheKey key)
 {
     this.Remove(key.ToString());
 }