【优化】移除EasyCaching.Core,EasyCaching.CSRedis,EasyCaching.InMemory等组件,直接使用原生CSRedis组件,替换SqlSugar二级缓存组件。

This commit is contained in:
程泰 孙
2023-04-03 15:29:52 +08:00
parent 8b7377de63
commit f1a72ac922
13 changed files with 370 additions and 295 deletions

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using CoreCms.Net.Caching.AutoMate.RedisCache;
using CoreCms.Net.Configuration;
using CSRedis;
using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
@@ -19,6 +20,13 @@ namespace CoreCms.Net.Core.Config
{
if (services == null) throw new ArgumentNullException(nameof(services));
if (AppSettingsConstVars.RedisUseCache)
{
//初始化Redis及分布式缓存
RedisHelper.Initialization(new CSRedisClient(AppSettingsConstVars.RedisConfigConnectionString));
}
services.AddTransient<IRedisOperationRepository, RedisOperationRepository>();
// 配置启动Redis服务虽然可能影响项目启动速度但是不能在运行的时候报错所以是合理的
@@ -34,6 +42,7 @@ namespace CoreCms.Net.Core.Config
return ConnectionMultiplexer.Connect(configuration);
});
}
}
}
}

View File

@@ -49,8 +49,7 @@ namespace CoreCms.Net.Core.Config
db.CurrentConnectionConfig.ConfigureExternalServices = new ConfigureExternalServices()
{
//判断是否开启redis设置二级缓存方式
//DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? (ICacheService)new SqlSugarRedisCache() : new SqlSugarMemoryCache()
DataInfoCacheService = new SqlSugarCache()
DataInfoCacheService = AppSettingsConstVars.RedisUseCache ? new SqlSugarRedisCache() : new SqlSugarMemoryCache()
};
db.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings()
{