CacheSetup.cs 740 B

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