Пример #1
0
        /// <summary>
        /// 注册默认Redis缓存
        /// </summary>
        /// <param name="services">服务</param>
        /// <param name="optionsAction">配置</param>
        public static void AddDefaultRedisCache(this ContainerBuilder services, Action <RedisCacheOptions> optionsAction)
        {
            services.CheckNotNull(nameof(services));
            optionsAction.CheckNotNull(nameof(optionsAction));

            var options = new RedisCacheOptions();

            optionsAction.Invoke(options);
            services.AddSingleton <ICacheSerializer, DefaultJsonFormatterSerializer>();
            services.AddSingleton <IRedisDatabaseProvider, RedisDatabaseProvider>();
            services.AddSingleton(options);
            services.AddSingleton <IRedisCacheProvider, DefaultRedisCacheProvider>();
            services.AddSingleton <ICacheProvider, DefaultRedisCacheProvider>();
        }
Пример #2
0
        /// <summary>
        /// 注册默认 混合Redis缓存
        /// </summary>
        /// <param name="services">服务</param>
        /// <param name="optionsAction">配置</param>
        public static void AddDefaultRedisCacheForHybrid(this ContainerBuilder services,
                                                         Action <RedisCacheOptions> optionsAction)
        {
            services.CheckNotNull(nameof(services));
            optionsAction.CheckNotNull(nameof(optionsAction));

            var options = new RedisCacheOptions();

            optionsAction.Invoke(options);
            services.AddSingleton(options);

            services.AddSingleton <ICacheSerializer, DefaultBinaryFormatterSerializer>();
            services.AddSingleton <IRedisDatabaseProvider, RedisDatabaseProvider>();
            services.AddSingleton <ICachingKeyGenerator, DefaultCachingKeyGenerator>();
            services.RegisterType <DefaultRedisCacheProvider>().SingleInstance();
        }
Пример #3
0
 /// <summary>
 /// 初始化一个<see cref="DefaultRedisCacheManager"/>类型的实例
 /// </summary>
 /// <param name="options">配置</param>
 /// <param name="log">日志</param>
 public DefaultRedisCacheManager(IOptions <RedisCacheOptions> options, ILog log)
 {
     _options = options.Value;
     _log     = log;
     _connectionMultiplexer = new Lazy <ConnectionMultiplexer>(CreateConnection, true);
 }
Пример #4
0
 /// <summary>
 /// 初始化一个<see cref="RedisCacheOptions"/>类型的实例
 /// </summary>
 /// <param name="options">Redis缓存配置</param>
 public RedisDatabaseProvider(RedisCacheOptions options)
 {
     _options = options;
     _connectionMultiplexer = new Lazy <ConnectionMultiplexer>(CreateConnectionMultiplexer);
 }