public bool Upate <T>(string key, T data, ObsloteType obsloteType, int cacheMin = 30) { bool ReturnBool = true; if (!Contains(key)) { ReturnBool = false; } else { _cache.Remove(key); Add(key, data, obsloteType, cacheMin); } return(ReturnBool); }
/// <summary> /// 添加 /// </summary> /// <param name="key"></param> /// <param name="data"></param> /// <param name="cacheMin"></param> /// <param name="obsloteType"></param> public void Add <T>(string key, T data, ObsloteType obsloteType = default, int cacheMin = 30) { if (obsloteType == ObsloteType.Absolutely) { _memoryCacheEntryOptions.AbsoluteExpiration = DateTime.Now.AddSeconds(cacheMin); } if (obsloteType == ObsloteType.Relative) { _memoryCacheEntryOptions.SlidingExpiration = TimeSpan.FromMinutes(cacheMin); } if (Contains(key)) { Upate <T>(key, data, obsloteType); } else { _cache.Set(key, data, _memoryCacheEntryOptions); } }