예제 #1
0
        public RedisProvider(IOptions <CacheManagerOptions> cacheManagerOptions)
        {
            var cacheOptions = cacheManagerOptions.Value.CacheOptions;
            var manager      = new CacheHitRatioManager(cacheManagerOptions.Value.HitRatioManagerUpdatePeriod);

            manager.Start();
            foreach (var kvDataBaseOptions in cacheOptions)
            {
                var cache = new RedisCache(kvDataBaseOptions.Value, manager);
                _redisCaches.Add(kvDataBaseOptions.Key, cache);
            }
        }
예제 #2
0
 public RedisCache(RedisOptions options, CacheHitRatioManager manager)
 {
     _options = options;
     _metricsTracingFactory =
         MetricsTracingFactory.CreateRedisMetricsFactory(nameof(RedisCache), _options.LongRequestTime);
     _serializeSettings = new JsonSerializerSettings
     {
         ContractResolver = new DefaultContractResolver {
             IgnoreShouldSerializeMembers = true
         }
     };
     _circuitBreakerPolicy = Policy.Handle <Exception>()
                             .CircuitBreakerAsync(_options.CircuitBreakerExceptionsCount, _options.CircuitBreakerSeconds);
     _policy = Policy.WrapAsync(Policy.TimeoutAsync(_options.RedisTimeout, TimeoutStrategy.Pessimistic),
                                _circuitBreakerPolicy);
     _counter = manager.CreateCounter(nameof(RedisCache));
 }