Beispiel #1
0
        public ICache BuildCache(string regionName, IDictionary <string, string> properties)
        {
            if (clientManagerStatic == null)
            {
                throw new InvalidOperationException(
                          "An 'IRedisClientsManager' must be configured with SetClientManager(). " +
                          "For example, call 'RedisCacheProvider(new PooledRedisClientManager())' " +
                          "before creating the ISessionFactory.");
            }

            if (log.IsDebugEnabled)
            {
                var sb = new StringBuilder();
                foreach (var pair in properties)
                {
                    sb.Append("name=");
                    sb.Append(pair.Key);
                    sb.Append("&value=");
                    sb.Append(pair.Value);
                    sb.Append(";");
                }
                log.Debug("building cache with region: " + regionName + ", properties: " + sb);
            }

            RedisCacheElement configElement = null;

            if (!String.IsNullOrWhiteSpace(regionName))
            {
                configElement = config.Caches[regionName];
            }

            return(BuildCache(regionName, properties, configElement, clientManagerStatic));
        }
        public RedisCache(string regionName, IDictionary<string, string> properties, RedisCacheElement element, ConnectionMultiplexer connectionMultiplexer, RedisCacheProviderOptions options)
        {
            this.connectionMultiplexer = connectionMultiplexer.ThrowIfNull("connectionMultiplexer");
            this.options = options.ThrowIfNull("options").ShallowCloneAndValidate();

            RegionName = regionName.ThrowIfNull("regionName");

            if (element == null)
            {
                expiry = TimeSpan.FromSeconds(
                    PropertiesHelper.GetInt32(Cfg.Environment.CacheDefaultExpiration, properties, DefaultExpiry)
                );
            }
            else
            {
                expiry = element.Expiration;
            }

            log.DebugFormat("using expiration : {0} seconds", expiry.TotalSeconds);

            var @namespace = CacheNamePrefix + RegionName;

            CacheNamespace = new RedisNamespace(@namespace);
            SyncInitialGeneration();
        }
Beispiel #3
0
        public ICache BuildCache(string regionName, IDictionary <string, string> properties)
        {
            if (connectionMultiplexerStatic == null)
            {
                throw new InvalidOperationException(
                          "A 'ConnectionMultiplexer' must be configured with SetConnectionMultiplexer(). " +
                          "For example, call 'RedisCacheProvider.SetConnectionMultiplexer(ConnectionMultiplexer.Connect(\"localhost:6379\"))' " +
                          "before creating the ISessionFactory."
                          );
            }

            // Double-check so that we don't have to lock if necessary.
            if (optionsStatic == null)
            {
                lock (syncRoot)
                {
                    if (optionsStatic == null)
                    {
                        optionsStatic = new RedisCacheProviderOptions();
                    }
                }
            }

            if (log.IsDebugEnabled)
            {
                var sb = new StringBuilder();
                foreach (var pair in properties)
                {
                    sb.Append("name=");
                    sb.Append(pair.Key);
                    sb.Append("&value=");
                    sb.Append(pair.Value);
                    sb.Append(";");
                }
                log.Debug("building cache with region: " + regionName + ", properties: " + sb);
            }

            RedisCacheElement configElement = null;

            if (!String.IsNullOrWhiteSpace(regionName))
            {
                configElement = providerSection.Caches[regionName];
            }

            return(BuildCache(regionName, properties, configElement, connectionMultiplexerStatic, optionsStatic));
        }
        public RedisCache(string regionName, IDictionary<string, string> properties, RedisCacheElement element, IRedisClientsManager clientManager)
        {
            this.serializer = new ObjectSerializer();
            this.clientManager = clientManager.ThrowIfNull("clientManager");
            this.RegionName = regionName.ThrowIfNull("regionName");

            this.expirySeconds = element != null 
                ? (int)element.Expiration.TotalSeconds
                : PropertiesHelper.GetInt32(Cfg.Environment.CacheDefaultExpiration, properties, DefaultExpiry);

            log.DebugFormat("using expiration : {0} seconds", this.expirySeconds);

            var regionPrefix = PropertiesHelper.GetString(Cfg.Environment.CacheRegionPrefix, properties, null);
            log.DebugFormat("using region prefix : {0}", regionPrefix);

            var namespacePrefix = CacheNamePrefix + this.RegionName;
            if (!String.IsNullOrWhiteSpace(regionPrefix))
            {
                namespacePrefix = regionPrefix + ":" + namespacePrefix;
            }

            this.CacheNamespace = new RedisNamespace(namespacePrefix);
            this.SyncGeneration();
        }
Beispiel #5
0
 protected virtual RedisCache BuildCache(string regionName, IDictionary <string, string> properties, RedisCacheElement configElement, ConnectionMultiplexer connectionMultiplexer, RedisCacheProviderOptions options)
 {
     return(new RedisCache(regionName, properties, configElement, connectionMultiplexer, options));
 }
 protected virtual RedisCache BuildCache(string regionName, IDictionary<string, string> properties, RedisCacheElement configElement, ConnectionMultiplexer connectionMultiplexer, RedisCacheProviderOptions options)
 {
     return new RedisCache(regionName, properties, configElement, connectionMultiplexer, options);
 }
Beispiel #7
0
 protected virtual RedisCache BuildCache(string regionName, IDictionary <string, string> properties, RedisCacheElement configElement, IRedisClientsManager clientManager)
 {
     return(new RedisCache(regionName, properties, configElement, clientManager));
 }
        public RedisCache(string regionName, IDictionary <string, string> properties, RedisCacheElement element, IRedisClientsManager clientManager)
        {
            this.serializer    = new ObjectSerializer();
            this.clientManager = clientManager.ThrowIfNull("clientManager");
            this.RegionName    = regionName.ThrowIfNull("regionName");

            this.expirySeconds = element != null
                ? (int)element.Expiration.TotalSeconds
                : PropertiesHelper.GetInt32(Cfg.Environment.CacheDefaultExpiration, properties, DefaultExpiry);

            log.DebugFormat("using expiration : {0} seconds", this.expirySeconds);

            var regionPrefix = PropertiesHelper.GetString(Cfg.Environment.CacheRegionPrefix, properties, null);

            log.DebugFormat("using region prefix : {0}", regionPrefix);

            var namespacePrefix = CacheNamePrefix + this.RegionName;

            if (!String.IsNullOrWhiteSpace(regionPrefix))
            {
                namespacePrefix = regionPrefix + ":" + namespacePrefix;
            }

            this.CacheNamespace = new RedisNamespace(namespacePrefix);
            this.SyncGeneration();
        }
Beispiel #9
0
 public void Add(RedisCacheElement element)
 {
     BaseAdd(element);
 }
        public RedisCache(string regionName, IDictionary <string, string> properties, RedisCacheElement element, ConnectionMultiplexer connectionMultiplexer, RedisCacheProviderOptions options)
        {
            this.connectionMultiplexer = connectionMultiplexer.ThrowIfNull("connectionMultiplexer");
            this.options = options.ThrowIfNull("options").ShallowCloneAndValidate();

            RegionName = regionName.ThrowIfNull("regionName");

            if (element == null)
            {
                expiry = TimeSpan.FromSeconds(
                    PropertiesHelper.GetInt32(Cfg.Environment.CacheDefaultExpiration, properties, DefaultExpiry)
                    );
            }
            else
            {
                expiry = element.Expiration;
            }

            log.DebugFormat("using expiration : {0} seconds", expiry.TotalSeconds);

            var @namespace = CacheNamePrefix + RegionName;

            CacheNamespace = new RedisNamespace(@namespace);
            SyncInitialGeneration();
        }
 protected virtual RedisCache BuildCache(string regionName, IDictionary<string, string> properties, RedisCacheElement configElement, IRedisClientsManager clientManager)
 {
     return new RedisCache(regionName, properties, configElement, clientManager);
 }
 public void Add(RedisCacheElement element)
 {
     BaseAdd(element);
 }