You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
588 B
28 lines
588 B
using NewLife.Caching;
|
|
|
|
namespace Cis.Core;
|
|
|
|
public static class CacheSetup
|
|
{
|
|
/// <summary>
|
|
/// 缓存注册(新生命Redis组件)
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
public static void AddCache(this IServiceCollection services)
|
|
{
|
|
services.AddSingleton<ICache>(options =>
|
|
{
|
|
var cacheOptions = App.GetOptions<CacheOptions>();
|
|
if (cacheOptions.CacheType == CacheTypeEnum.Redis.ToString())
|
|
{
|
|
var redis = new Redis();
|
|
redis.Init(cacheOptions.RedisConnectionString);
|
|
return redis;
|
|
}
|
|
else
|
|
{
|
|
return Cache.Default;
|
|
}
|
|
});
|
|
}
|
|
}
|