重写SqlSugar二级缓存模糊删除缓存方法覆盖ICacheService实现类SqlSugarCache中的GetAllKey和Remove方法解决是否含有key前缀不一致问题,ipratelimit接入分布式缓存

This commit is contained in:
2023-10-08 16:36:32 +08:00
parent c592925096
commit e7fe909fd0
8 changed files with 28 additions and 19 deletions
+2 -3
View File
@@ -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);
}
}
}
@@ -17,8 +17,8 @@ namespace ZR.Infrastructure.WebExtensions
//从appsettings.json中加载Ip规则
services.Configure<IpRateLimitPolicies>(configuration.GetSection("IpRateLimitPolicies"));
//注入计数器和规则存储
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
services.AddSingleton<IIpPolicyStore, DistributedCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, DistributedCacheRateLimitCounterStore>();
//配置(解析器、计数器密钥生成器)
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>();