using EasyCaching.Core; namespace SqlSugar; /// /// SqlSugar ORM框架所需缓存配置 /// public class SqlSugarCache : ICacheService { private static readonly IEasyCachingProvider Cache = App.GetRequiredService(); public void Add(string key, V value) { Cache.Set(key, value, TimeSpan.MaxValue); } public void Add(string key, V value, int cacheDurationInSeconds) { Cache.Set(key, value, TimeSpan.FromSeconds(cacheDurationInSeconds)); } public bool ContainsKey(string key) { return Cache.Exists(key); } public V Get(string key) { return Cache.Get(key).Value; } public IEnumerable GetAllKey() { return Cache.GetByPrefix("SqlSugarDataCache.").Keys; } public void Remove(string key) { Cache.Remove(key); } public V GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = 2147483647) { if (Cache.Exists(cacheKey)) { return Cache.Get(cacheKey).Value; } V v = create(); Cache.Set(cacheKey, v, TimeSpan.FromSeconds(cacheDurationInSeconds)); return v; } }