From 807e4b1c070e536bc1b22561d7ba5efa5cd64ae5 Mon Sep 17 00:00:00 2001 From: lqc <15342622+aq982@user.noreply.gitee.com> Date: Mon, 10 Mar 2025 02:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Cache/SysCacheService.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs b/Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs index f4589562..e9d6d0d3 100644 --- a/Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs @@ -146,7 +146,7 @@ public class SysCacheService : IDynamicApiController, ISingleton private static string KeySingle(object t) { - return t.GetType().IsClass && !t.GetType().IsPrimitive ? JsonConvert.SerializeObject(t) : t.ToString(); + return t.GetType().IsClass && !t.GetType().IsPrimitive ? JSON.Serialize(t) : t.ToString(); } /// @@ -155,7 +155,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public TimeSpan GetExpire(string key) + public static TimeSpan GetExpire(string key) { return _cacheProvider.Cache.GetExpire(key); } @@ -505,7 +505,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// 过期时间,单位秒 /// [NonAction] - public T GetOrAdd(string key, Func callback, int expire = -1) + public T GetOrAdd(string key, Func callback, int expire = -1) { if (string.IsNullOrWhiteSpace(key)) return default; return _cacheProvider.Cache.GetOrAdd($"{_cacheOptions.Prefix}{key}", callback, expire); @@ -518,7 +518,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public IDictionary GetHashMap(string key) + public static IDictionary GetHashMap(string key) { return _cacheProvider.Cache.GetDictionary(key); } @@ -531,7 +531,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public bool HashSet(string key, Dictionary dic) + public static bool HashSet(string key, Dictionary dic) { var hash = GetHashMap(key); foreach (var v in dic) @@ -549,7 +549,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public void HashAdd(string key, string hashKey, T value) + public static void HashAdd(string key, string hashKey, T value) { var hash = GetHashMap(key); hash.Add(hashKey, value); @@ -563,7 +563,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public void HashAddOrUpdate(string key, string hashKey, T value) + public static void HashAddOrUpdate(string key, string hashKey, T value) { var hash = GetHashMap(key); if (hash.ContainsKey(hashKey)) @@ -580,7 +580,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public List HashGet(string key, params string[] fields) + public static List HashGet(string key, params string[] fields) { var hash = GetHashMap(key); return hash.Where(t => fields.Any(c => t.Key == c)).Select(t => t.Value).ToList(); @@ -594,20 +594,20 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public T HashGetOne(string key, string field) + public static T HashGetOne(string key, string field) { var hash = GetHashMap(key); return hash.TryGetValue(field, out T value) ? value : default; } // 新增方法:获取哈希表所有键 - public List HashGetAllKeys(string key) + public static List HashGetAllKeys(string key) { var hash = GetHashMap(key); // 假设值为任意类型 return hash.Keys.ToList(); } // 增强的哈希设置方法(带过期时间) - public bool HashSet(string key, Dictionary items, TimeSpan? expiry = null) + public static bool HashSet(string key, Dictionary items, TimeSpan? expiry = null) { var hash = GetHashMap(key); foreach (var item in items) @@ -622,7 +622,7 @@ public class SysCacheService : IDynamicApiController, ISingleton return true; } // 异步批量设置哈希,目前没有,先保留扩展 - public async Task HashSetAsync(string key, Dictionary items, TimeSpan? expiry = null) + public static async Task HashSetAsync(string key, Dictionary items, TimeSpan? expiry = null) { var hash = GetHashMap(key); foreach (var item in items) @@ -645,7 +645,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public IDictionary HashGetAll(string key) + public static IDictionary HashGetAll(string key) { var hash = GetHashMap(key); return hash; @@ -659,7 +659,7 @@ public class SysCacheService : IDynamicApiController, ISingleton /// /// [NonAction] - public int HashDel(string key, params string[] fields) + public static int HashDel(string key, params string[] fields) { var hash = GetHashMap(key); fields.ToList().ForEach(t => hash.Remove(t));