using NewLife.Caching; namespace Cis.Core; /// /// SqlSugar二级缓存(必须是内存缓存) /// public class SqlSugarCache : ICacheService, ISingleton { private static readonly ICache _cache = Cache.Default; public void Add(string key, V value) { _cache.Set(key, value); } public void Add(string key, V value, int cacheDurationInSeconds) { _cache.Set(key, value, cacheDurationInSeconds); } public bool ContainsKey(string key) { return _cache.ContainsKey(key); } public V Get(string key) { return _cache.Get(key); } public IEnumerable GetAllKey() { return _cache.Keys; } public V GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = int.MaxValue) { if (!_cache.TryGetValue(cacheKey, out V value)) { value = create(); _cache.Set(cacheKey, value, cacheDurationInSeconds); } return value; } public void Remove(string key) { _cache.Remove(key); } }