using ZR.Common; using ZR.Common.Cache; namespace ZR.Admin.WebApi.Extensions { public class SqlSugarCache : SqlSugar.ICacheService { public void Add(string key, V value) { //RedisServer.Cache.Set(key, value, 3600 + RedisHelper.RandomExpired(5, 30)); CacheHelper.SetCache(key, value); } public void Add(string key, V value, int cacheDurationInSeconds) { //RedisServer.Cache.Set(key, value, cacheDurationInSeconds); CacheHelper.SetCaches(key, value, cacheDurationInSeconds); } public bool ContainsKey(string key) { //return RedisServer.Cache.Exists(key); return CacheHelper.Exists(key); } public V Get(string key) { //return RedisServer.Cache.Get(key); return (V)CacheHelper.Get(key); } public IEnumerable GetAllKey() { return RedisServer.Cache.Keys("*"); } public V GetOrCreate(string cacheKey, Func create, int cacheDurationInSeconds = int.MaxValue) { if (RedisServer.Cache.Exists(cacheKey)) { return Get(cacheKey); } else { var restul = create(); Add(cacheKey, restul); return restul; } } public void Remove(string key) { RedisServer.Cache.Del(key); } } }