CacheSetup.cs 621 B

1234567891011121314151617181920212223
  1. namespace Admin.NET.Core;
  2. public static class CacheSetup
  3. {
  4. /// <summary>
  5. /// 缓存注册(新生命Redis组件)
  6. /// </summary>
  7. /// <param name="services"></param>
  8. public static void AddCache(this IServiceCollection services)
  9. {
  10. ICache cache = Cache.Default;
  11. var cacheOptions = App.GetOptions<CacheOptions>();
  12. if (cacheOptions.CacheType == CacheTypeEnum.Redis.ToString())
  13. {
  14. var redis = new FullRedis();
  15. redis.Init(cacheOptions.RedisConnectionString);
  16. cache = redis;
  17. }
  18. services.AddSingleton(cache);
  19. }
  20. }