CacheSetup.cs 645 B

123456789101112131415161718192021222324
  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 ICache 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. return cache;
  20. }
  21. }