/// <summary> /// Initializes a new instance of the <see cref="RedisCacheBackPlate"/> class. /// </summary> /// <param name="configuration">The cache manager configuration.</param> /// <param name="cacheName">The cache name.</param> public RedisCacheBackPlate(CacheManagerConfiguration configuration, string cacheName) : base(configuration, cacheName) { if (configuration == null) { throw new ArgumentNullException("configuration"); } this.channelName = string.Format( CultureInfo.InvariantCulture, "CacheManagerBackPlate_{0}", cacheName); this.identifier = Guid.NewGuid().ToString(); RetryHelper.Retry( () => { // throws an exception if not found for the name var cfg = RedisConfigurations.GetConfiguration(this.Name); var connection = RedisConnectionPool.Connect(cfg); this.redisSubscriper = connection.GetSubscriber(); }, configuration.RetryTimeout, configuration.MaxRetries); this.Subscribe(); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting /// unmanaged resources. /// </summary> /// <param name="disposeManaged">Indicator if managed resources should be released.</param> protected override void Dispose(bool disposeManaged) { base.Dispose(disposeManaged); if (disposeManaged) { RedisConnectionPool.DisposeConnection(this.RedisConfiguration); } }
/// <summary> /// Initializes a new instance of the <see cref="RedisCacheBackPlate"/> class. /// </summary> /// <param name="configuration">The cache manager configuration.</param> /// <param name="loggerFactory">The logger factory</param> public RedisCacheBackPlate(CacheManagerConfiguration configuration, ILoggerFactory loggerFactory) : base(configuration) { NotNull(configuration, nameof(configuration)); NotNull(loggerFactory, nameof(loggerFactory)); this.logger = loggerFactory.CreateLogger(this); this.channelName = configuration.BackPlateChannelName ?? "CacheManagerBackPlate"; this.identifier = Guid.NewGuid().ToString(); RetryHelper.Retry( () => { // throws an exception if not found for the name var cfg = RedisConfigurations.GetConfiguration(this.ConfigurationKey); var connection = RedisConnectionPool.Connect(cfg); this.redisSubscriper = connection.GetSubscriber(); }, configuration.RetryTimeout, configuration.MaxRetries, this.logger); this.Subscribe(); this.timer = new Timer( (obj) => { lock (this.messageLock) { try { if (this.messages != null && this.messages.Count > 0) { var msgs = string.Join(",", this.messages); if (this.logger.IsEnabled(LogLevel.Debug)) { this.logger.LogDebug("Back-plate is sending {0} messages ({1} skipped).", this.messages.Count, this.skippedMessages); } this.Publish(msgs); this.skippedMessages = 0; this.messages.Clear(); } } catch (Exception ex) { this.logger.LogError(ex, "Error occurred sending back plate messages."); throw; } } }, this, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100)); }
/// <summary> /// Initializes a new instance of the <see cref="RedisCacheBackPlate"/> class. /// </summary> /// <param name="configuration">The cache manager configuration.</param> public RedisCacheBackPlate(CacheManagerConfiguration configuration) : base(configuration) { NotNull(configuration, nameof(configuration)); this.channelName = configuration.BackPlateChannelName ?? "CacheManagerBackPlate"; this.identifier = Guid.NewGuid().ToString(); RetryHelper.Retry( () => { // throws an exception if not found for the name var cfg = RedisConfigurations.GetConfiguration(this.ConfigurationKey); var connection = RedisConnectionPool.Connect(cfg); this.redisSubscriper = connection.GetSubscriber(); }, configuration.RetryTimeout, configuration.MaxRetries); this.Subscribe(); }