瀏覽代碼

😁缓存键值增加不为空判断

zuohuaijun 2 年之前
父節點
當前提交
fc7ae18881
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs

+ 6 - 0
Admin.NET/Admin.NET.Core/Service/Cache/SysCacheService.cs

@@ -45,6 +45,8 @@ public class SysCacheService : IDynamicApiController, ISingleton
     [NonAction]
     public bool Set(string key, object value)
     {
+        if (string.IsNullOrWhiteSpace(key)) return false;
+
         return _cache.Set($"{_cacheOptions.Prefix}{key}", value);
     }
 
@@ -58,6 +60,8 @@ public class SysCacheService : IDynamicApiController, ISingleton
     [NonAction]
     public bool Set(string key, object value, TimeSpan expire)
     {
+        if (string.IsNullOrWhiteSpace(key)) return false;
+
         return _cache.Set($"{_cacheOptions.Prefix}{key}", value, expire);
     }
 
@@ -149,6 +153,8 @@ public class SysCacheService : IDynamicApiController, ISingleton
     [NonAction]
     public T GetOrAdd<T>(string key, Func<string, T> callback, int expire = -1)
     {
+        if (string.IsNullOrWhiteSpace(key)) return default;
+
         return _cache.GetOrAdd($"{_cacheOptions.Prefix}{key}", callback, expire);
     }
 }