示例#1
0
        public RedisCacheNotifier(string cacheName, RedisCacheNotifierPolicy policy)
        {
            this.policy    = policy;
            this.cacheName = cacheName;
            this.sender    = Guid.NewGuid().ToString();
            this.convert   = RedisConverterFactory.CreateConverter(policy.Converter);

            this.client = new RedisClient(policy.ConnectionString, policy.ClusterType, policy.MonitorPort,
                                          policy.MonitorIntervalMilliseconds);
        }
示例#2
0
        public RedisCacheNotifier(string name, RedisCacheNotifierPolicy policy)
        {
            this.name   = name;
            this.policy = policy;

            this.log = NLog.LogManager.GetLogger(typeof(RedisCacheNotifier).FullName);

            this.cacheSubClients = new ConcurrentDictionary <string, RedisClient>(StringComparer.InvariantCultureIgnoreCase);
            this.cacheCallbacks  = new ConcurrentDictionary <string, Func <CacheItemNotification, bool> >(StringComparer.InvariantCultureIgnoreCase);

            if (policy == null)
            {
                log.Error("Invalid Policy for Cache {0}", this.name);
                throw new ArgumentNullException(nameof(policy));
            }

            if (!string.IsNullOrEmpty(policy.ConnectionName))
            {
                this.connectionString = CacheManager.GetConnectionString(policy.ConnectionName)?.ConnectionString;

                if (string.IsNullOrEmpty(connectionString))
                {
                    throw new ArgumentException(
                              $"{nameof(ICacheConnectionString.ConnectionString)} not found for {nameof(policy.ConnectionName)} {policy.ConnectionName}", $"{nameof(policy)}.{nameof(policy.ConnectionName)}");
                }
            }
            else if (!string.IsNullOrEmpty(policy.ConnectionString))
            {
                this.connectionString = policy.ConnectionString;
            }
            else
            {
                throw new ArgumentException(
                          $"{nameof(policy.ConnectionString)} is undefined", $"{nameof(policy)}.{nameof(policy.ConnectionString)}");
            }

            this.sender  = Guid.NewGuid().ToString();
            this.convert = RedisConverterFactory.CreateConverter(policy.Converter);

            SubscribeToGeneralInvalidationMessage(policy.GeneralInvalidationChannel);
        }
示例#3
0
 public ScopedCacheContext(String connectionName, String converterType)
 {
     this.convert = RedisConverterFactory.CreateConverter(converterType);
     this.client  = RedisClient.GetNamedRedisClient(connectionName);
     RegisterToRedisConnectionStateChangeEvent();
 }
示例#4
0
 public ScopedCacheContext(String connectionString, String converterType, String clusterType, int monitorPort, int monitorIntervalMilliseconds)
 {
     this.convert = RedisConverterFactory.CreateConverter(converterType);
     this.client  = new RedisClient(connectionString, clusterType, monitorPort, monitorIntervalMilliseconds);
     RegisterToRedisConnectionStateChangeEvent();
 }
示例#5
0
 public CacheContext(String connectionName, String converterType)
 {
     this.convert = RedisConverterFactory.CreateConverter(converterType);
     this.client  = RedisClient.GetNamedRedisClient(connectionName);
 }