public void Set_section_no_detail_then_read()
        {
            var section = new CacheConfigurationSection {
                Pattern           = "{region}/{key}",
                FormatNullRegion  = true,
                MaxExpirationHour = 1D,
            };

            //with region
            {
                var config = CacheConfigBuilder.Build(typeof(MemoryCacheProvider), "anyRegion", section);
                Assert.AreNotEqual(config, CacheConfig.Empty);

                Assert.AreEqual(config.Pattern, "{0}/{1}");
                Assert.AreEqual(config.FormatNullRegion, section.FormatNullRegion);
                Assert.AreEqual(config.MaxExpiration.Value.TotalHours, section.MaxExpirationHour);
            }

            //without region
            {
                var config = CacheConfigBuilder.Build(typeof(RedisCacheProvider), null, section);
                Assert.AreNotEqual(config, CacheConfig.Empty);

                Assert.AreEqual(config.Pattern, "{0}/{1}");
                Assert.AreEqual(config.FormatNullRegion, section.FormatNullRegion);
                Assert.AreEqual(config.MaxExpiration.Value.TotalHours, section.MaxExpirationHour);
            }
        }
        public void Set_section_with_detail_then_read()
        {
            var section = new CacheConfigurationSection {
                Pattern           = "{region}/{key}",
                FormatNullRegion  = true,
                MaxExpirationHour = 1D,
                Details           = new CacheItemElementCollection()
            };
            var detail = new CacheItemDetailElement {
                Region            = "someRegion",
                Pattern           = "{region}//{key}",
                Provider          = typeof(RedisCacheProvider).FullName,
                MaxExpirationHour = 2D,
                FormatNullRegion  = false,
            };

            section.Details.Add(detail);

            //with region
            {
                var config = CacheConfigBuilder.Build(typeof(MemoryCacheProvider), "otherRegion", section);
                Assert.AreNotEqual(config, CacheConfig.Empty);

                Assert.AreEqual(config.Pattern, "{0}/{1}");
                Assert.AreEqual(config.FormatNullRegion, section.FormatNullRegion);
                Assert.AreEqual(config.MaxExpiration.Value.TotalHours, section.MaxExpirationHour);
            }

            //without region
            {
                var config = CacheConfigBuilder.Build(typeof(RedisCacheProvider), null, section);
                Assert.AreNotEqual(config, CacheConfig.Empty);

                Assert.AreEqual(config.Pattern, "{0}/{1}");
                Assert.AreEqual(config.FormatNullRegion, section.FormatNullRegion);
                Assert.AreEqual(config.MaxExpiration.Value.TotalHours, section.MaxExpirationHour);
            }

            //with other region
            {
                var config = CacheConfigBuilder.Build(typeof(RedisCacheProvider), "otherRegion", section);
                Assert.AreNotEqual(config, CacheConfig.Empty);

                Assert.AreEqual(config.Pattern, "{0}/{1}");
                Assert.AreEqual(config.FormatNullRegion, section.FormatNullRegion);
                Assert.AreEqual(config.MaxExpiration.Value.TotalHours, section.MaxExpirationHour);
            }

            //with correct region
            {
                var config = CacheConfigBuilder.Build(typeof(RedisCacheProvider), "someRegion", section);
                Assert.AreNotEqual(config, CacheConfig.Empty);

                Assert.AreEqual(config.Pattern, "{0}//{1}");
                Assert.AreEqual(config.FormatNullRegion, detail.FormatNullRegion);
                Assert.AreEqual(config.MaxExpiration.Value.TotalHours, detail.MaxExpirationHour);
            }
        }
Пример #3
0
        public ICacheProvider Switch(String region)
        {
            if (!String.IsNullOrWhiteSpace(Region))
            {
                throw new InvalidOperationException();
            }
            var config = CacheConfigBuilder.Build(typeof(RedisCacheProvider), region);

            return(new RedisCacheProvider(_connection, region, config));
        }
Пример #4
0
 public RedisCacheProvider(IConnectionMultiplexer connection, String region)
     : this(connection, region, CacheConfigBuilder.Build(typeof(RedisCacheProvider), region))
 {
 }
Пример #5
0
 public RedisCacheProvider(String configuration, String region)
     : this(configuration, region, CacheConfigBuilder.Build(typeof(RedisCacheProvider), region))
 {
 }
Пример #6
0
 public MemcachedCacheProvider(MemcachedClient client, String region)
     : this(client, region, CacheConfigBuilder.Build(typeof(MemcachedCacheProvider), region))
 {
 }