diff --git a/ZR.Admin.WebApi/Extensions/SqlSugarCache.cs b/ZR.Admin.WebApi/Extensions/SqlSugarCache.cs index 8b9595b..8354e63 100644 --- a/ZR.Admin.WebApi/Extensions/SqlSugarCache.cs +++ b/ZR.Admin.WebApi/Extensions/SqlSugarCache.cs @@ -1,4 +1,5 @@ -using ZR.Common.Cache; +using ZR.Common; +using ZR.Common.Cache; namespace ZR.Admin.WebApi.Extensions { @@ -6,22 +7,26 @@ namespace ZR.Admin.WebApi.Extensions { public void Add(string key, V value) { - RedisServer.Cache.Set(key, value, 3600 + RedisHelper.RandomExpired(5, 30)); + //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); + //RedisServer.Cache.Set(key, value, cacheDurationInSeconds); + CacheHelper.SetCaches(key, value, cacheDurationInSeconds); } public bool ContainsKey(string key) { - return RedisServer.Cache.Exists(key); + //return RedisServer.Cache.Exists(key); + return CacheHelper.Exists(key); } public V Get(string key) { - return RedisServer.Cache.Get(key); + //return RedisServer.Cache.Get(key); + return (V)CacheHelper.Get(key); } public IEnumerable GetAllKey() diff --git a/ZR.Common/Cache/CacheHelper.cs b/ZR.Common/Cache/CacheHelper.cs index 0fc6625..3d82255 100644 --- a/ZR.Common/Cache/CacheHelper.cs +++ b/ZR.Common/Cache/CacheHelper.cs @@ -106,6 +106,18 @@ namespace ZR.Common { Cache.Remove(key); } + + /// + /// 验证缓存项是否存在 + /// + /// 缓存Key + /// + public static bool Exists(string key) + { + if (key == null) + throw new ArgumentNullException(nameof(key)); + return Cache.TryGetValue(key, out _); + } } }