public void SlidingExpiryTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); CacheItemPolicy policy = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromSeconds(4) }; provider.Set("key8", "data8", policy, "testRegion"); // Wait for 500 seconds, get the data to reset the exiration System.Threading.Thread.Sleep(2000); object data = provider.Get("key8", "testRegion"); Assert.Equal("data8", data); // 1.1 sec after intial insert, but should still be there. System.Threading.Thread.Sleep(2400); data = provider.Get("key8", "testRegion"); Assert.Equal("data8", data); // Wait for 1.1 seconds so that data will expire System.Threading.Thread.Sleep(4400); data = provider.Get("key8", "testRegion"); Assert.Equal(null, data); } }
public void AddScriptFixForExpiryTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); DateTime utxExpiry = DateTime.UtcNow.AddSeconds(1); provider.Add("key9", "data9", utxExpiry, "testRegion"); object data = provider.Get("key9", "testRegion"); Assert.Equal("data9", data); // Wait for 1.1 seconds so that data will expire System.Threading.Thread.Sleep(1100); data = provider.Get("key9", "testRegion"); Assert.Equal(null, data); } }
public void GetWithoutSetTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); Assert.Equal(null, provider.Get("key1")); } }
public void RegionsTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); DateTime utxExpiry = DateTime.UtcNow.AddMinutes(3); provider.Set("key11", "data11.1", utxExpiry, "region1"); provider.Set("key11", "data11.2", utxExpiry, "region2"); object region1Data = provider.Get("key11", "region1"); object region2Data = provider.Get("key11", "region2"); object regionlessData = provider.Get("key11"); Assert.Equal("data11.1", region1Data); Assert.Equal("data11.2", region2Data); Assert.Equal(null, regionlessData); } }
public void TryGet() { var fake = A.Fake <IObjectCacheConnection>(); A.CallTo(() => fake.Get("key1", null)).Returns(new ArgumentException("foo")); RedisObjectCache cache = new RedisObjectCache("unitTest", new NameValueCollection()); cache.cache = fake; var obj = cache.Get("key1"); Assert.IsType <ArgumentException>(obj); }
public void RemoveWithoutSetTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); provider.Remove("key6", "testRegion"); object data = provider.Get("key6", "testRegion"); Assert.Equal(null, data); } }
public void GetWithSlidingExpiration() { var fake = A.Fake <IObjectCacheConnection>(); A.CallTo(() => fake.Get("key1", null)).Returns(new SlidingExpiryCacheItem("foo", TimeSpan.FromMinutes(1))); RedisObjectCache cache = new RedisObjectCache("unitTest", new NameValueCollection()); cache.cache = fake; var obj = cache.Get("key1"); Assert.Equal("foo", obj); A.CallTo(() => fake.ResetExpiry("key1", A <DateTime> .Ignored, null)).MustHaveHappened(); }
public void SetGetTest() { using (new RedisServer()) { NameValueCollection config = new NameValueCollection(); config.Add("ssl", "false"); RedisObjectCache provider = new RedisObjectCache("test", config); DateTime utxExpiry = DateTime.UtcNow.AddSeconds(3); provider.Set("key2", "data2", utxExpiry, "testRegion"); object data = provider.Get("key2", "testRegion"); Assert.Equal("data2", data); } }