public static string Generate(MemoryCacheKey key, string identifier = "") { if (string.IsNullOrEmpty(identifier)) { return(key.ToString()); } return($"{key.ToString()}_{identifier}"); }
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); }
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)); }
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); } }
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); } }
public void Remove(MemoryCacheKey key) { this.Remove(key.ToString()); }