Преглед изворни кода

增加系统配置缓存前缀

林海波 пре 1 година
родитељ
комит
c90ded2cc9

+ 5 - 0
Admin.NET/Admin.NET.Core/Const/CacheConst.cs

@@ -80,4 +80,9 @@ public class CacheConst
     /// 登录黑名单
     /// </summary>
     public const string KeyBlacklist = "sys_blacklist:";
+
+    /// <summary>
+    /// 系统配置缓存
+    /// </summary>
+    public const string KeyConfig = "sys_config:";
 }

+ 6 - 6
Admin.NET/Admin.NET.Core/Service/Config/SysConfigService.cs

@@ -81,7 +81,7 @@ public class SysConfigService : IDynamicApiController, ITransient
         var config = input.Adapt<SysConfig>();
         await _sysConfigRep.AsUpdateable(config).IgnoreColumns(true).ExecuteCommandAsync();
 
-        _sysCacheService.Remove(config.Code);
+        _sysCacheService.Remove($"{CacheConst.KeyConfig}{config.Code}");
     }
 
     /// <summary>
@@ -99,7 +99,7 @@ public class SysConfigService : IDynamicApiController, ITransient
 
         await _sysConfigRep.DeleteAsync(config);
 
-        _sysCacheService.Remove(config.Code);
+        _sysCacheService.Remove($"{CacheConst.KeyConfig}{config.Code}");
     }
 
     /// <summary>
@@ -119,7 +119,7 @@ public class SysConfigService : IDynamicApiController, ITransient
 
             await _sysConfigRep.DeleteAsync(config);
 
-            _sysCacheService.Remove(config.Code);
+            _sysCacheService.Remove($"{CacheConst.KeyConfig}{config.Code}");
         }
     }
 
@@ -144,12 +144,12 @@ public class SysConfigService : IDynamicApiController, ITransient
     {
         if (string.IsNullOrWhiteSpace(code)) return default;
 
-        var value = _sysCacheService.Get<string>(code);
+        var value = _sysCacheService.Get<string>($"{CacheConst.KeyConfig}{code}");
         if (string.IsNullOrEmpty(value))
         {
             var config = await _sysConfigRep.GetFirstAsync(u => u.Code == code);
             value = config != null ? config.Value : default;
-            _sysCacheService.Set(code, value);
+            _sysCacheService.Set($"{CacheConst.KeyConfig}{code}", value);
         }
         if (string.IsNullOrWhiteSpace(value)) return default;
         return (T)Convert.ChangeType(value, typeof(T));
@@ -170,7 +170,7 @@ public class SysConfigService : IDynamicApiController, ITransient
         config.Value = value;
         await _sysConfigRep.AsUpdateable(config).ExecuteCommandAsync();
 
-        _sysCacheService.Remove(config.Code);
+        _sysCacheService.Remove($"{CacheConst.KeyConfig}{config.Code}");
     }
 
     /// <summary>