Browse Source

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

zuohuaijun 2 years ago
parent
commit
fc7ae18881
1 changed files with 6 additions and 0 deletions
  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);
     }
 }