diff --git a/Infrastructure/Cache/RedisServer.cs b/Infrastructure/Cache/RedisServer.cs index a44c178..53d3357 100644 --- a/Infrastructure/Cache/RedisServer.cs +++ b/Infrastructure/Cache/RedisServer.cs @@ -1,8 +1,7 @@ using CSRedis; using Infrastructure; -using Microsoft.Extensions.Caching.Distributed; -namespace ZR.Common.Cache +namespace ZR.Infrastructure.Cache { public class RedisServer { @@ -13,7 +12,7 @@ namespace ZR.Common.Cache { Cache = new CSRedisClient(AppSettings.GetConfig("RedisServer:Cache")); Session = new CSRedisClient(AppSettings.GetConfig("RedisServer:Session")); - RedisHelper.Initialization(Cache); + RedisHelper.Initialization(Session); } } } diff --git a/Infrastructure/WebExtensions/IPRateExtension.cs b/Infrastructure/WebExtensions/IPRateExtension.cs index 2eccadf..71d3792 100644 --- a/Infrastructure/WebExtensions/IPRateExtension.cs +++ b/Infrastructure/WebExtensions/IPRateExtension.cs @@ -17,8 +17,8 @@ namespace ZR.Infrastructure.WebExtensions //从appsettings.json中加载Ip规则 services.Configure(configuration.GetSection("IpRateLimitPolicies")); //注入计数器和规则存储 - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); //配置(解析器、计数器密钥生成器) services.AddSingleton(); services.AddSingleton(); diff --git a/ZR.Admin.WebApi/Program.cs b/ZR.Admin.WebApi/Program.cs index 5558e1c..d636823 100644 --- a/ZR.Admin.WebApi/Program.cs +++ b/ZR.Admin.WebApi/Program.cs @@ -1,4 +1,3 @@ -using System.Reflection; using AspNetCoreRateLimit; using Infrastructure.Converter; using Microsoft.AspNetCore.DataProtection; @@ -8,9 +7,8 @@ using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Redis; using Microsoft.Extensions.Options; using Newtonsoft.Json; -using Quartz; using ZR.Admin.WebApi.Extensions; -using ZR.Common.Cache; +using ZR.Infrastructure.Cache; using ZR.Infrastructure.Resolver; using ZR.Infrastructure.WebExtensions; using ZR.ServiceCore.Model; diff --git a/ZR.CodeGenerator/ZR.CodeGenerator.csproj b/ZR.CodeGenerator/ZR.CodeGenerator.csproj index 620ceae..dba0753 100644 --- a/ZR.CodeGenerator/ZR.CodeGenerator.csproj +++ b/ZR.CodeGenerator/ZR.CodeGenerator.csproj @@ -12,6 +12,6 @@ - + diff --git a/ZR.Model/ZR.Model.csproj b/ZR.Model/ZR.Model.csproj index 22b5ee1..8aafae9 100644 --- a/ZR.Model/ZR.Model.csproj +++ b/ZR.Model/ZR.Model.csproj @@ -9,7 +9,7 @@ - + diff --git a/ZR.Repository/ZR.Repository.csproj b/ZR.Repository/ZR.Repository.csproj index d5e0de2..0f43c8c 100644 --- a/ZR.Repository/ZR.Repository.csproj +++ b/ZR.Repository/ZR.Repository.csproj @@ -13,6 +13,6 @@ - + diff --git a/ZR.ServiceCore/SqlSugar/SqlSugarCache.cs b/ZR.ServiceCore/SqlSugar/SqlSugarCache.cs index f9d5e4a..16ce939 100644 --- a/ZR.ServiceCore/SqlSugar/SqlSugarCache.cs +++ b/ZR.ServiceCore/SqlSugar/SqlSugarCache.cs @@ -1,5 +1,4 @@ -using ZR.Common; -using ZR.Common.Cache; +using ZR.Infrastructure.Cache; namespace ZR.ServiceCore.SqlSugar { @@ -31,7 +30,10 @@ namespace ZR.ServiceCore.SqlSugar public IEnumerable GetAllKey() { - return RedisServer.Cache.Keys("*"); + var keys = RedisServer.Cache.Keys("cache:SqlSugarDataCache.*"); + // return RedisServer.Cache.Keys("cache:SqlSugarDataCache.*"); + keys = keys.Select(it => it.Replace("cache:", "")).ToArray(); + return keys; // return CacheHelper.GetCacheKeys(); } @@ -51,15 +53,16 @@ namespace ZR.ServiceCore.SqlSugar } else { - var restul = create(); + var result = create(); - Add(cacheKey, restul, cacheDurationInSeconds); - return restul; + Add(cacheKey, result, cacheDurationInSeconds); + return result; } } public void Remove(string key) { + // key = key.Split("cache:")[1]; RedisServer.Cache.Del(key); // CacheHelper.Remove(key); } diff --git a/ZR.ServiceCore/SqlSugar/SqlsugarSetup.cs b/ZR.ServiceCore/SqlSugar/SqlSugarSetup.cs similarity index 95% rename from ZR.ServiceCore/SqlSugar/SqlsugarSetup.cs rename to ZR.ServiceCore/SqlSugar/SqlSugarSetup.cs index c161d07..fea608a 100644 --- a/ZR.ServiceCore/SqlSugar/SqlsugarSetup.cs +++ b/ZR.ServiceCore/SqlSugar/SqlSugarSetup.cs @@ -4,12 +4,12 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using SqlSugar.IOC; -using ZR.Model.System; +using ZR.Infrastructure.Cache; using ZR.ServiceCore.Model; namespace ZR.ServiceCore.SqlSugar { - public static class SqlsugarSetup + public static class SqlSugarSetup { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); @@ -56,6 +56,15 @@ namespace ZR.ServiceCore.SqlSugar { InitTable.InitDb(); } + + StaticConfig.CacheRemoveByLikeStringFunc = (service, key) => + { + var keyList = RedisServer.Cache.Keys("cache:SqlSugarDataCache" + key + "*"); + foreach (var item in keyList) + { + RedisServer.Cache.Del(item.Split("cache:")[1]); + } + }; } ///