Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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 TrySet()
        {
            var fake = A.Fake <IObjectCacheConnection>();

            A.CallTo(() => fake.Set("key1", "object", A <DateTime> .Ignored, null));
            DateTime         utcExpiry = DateTime.Now;
            RedisObjectCache cache     = new RedisObjectCache("unitTest", new NameValueCollection());

            cache.cache = fake;
            cache.Set("key1", "object", utcExpiry);
            A.CallTo(() => fake.Set("key1", "object", A <DateTime> .Ignored, null)).MustHaveHappened();
        }
Esempio n. 4
0
        public void ContainsTest()
        {
            using (new RedisServer())
            {
                NameValueCollection config = new NameValueCollection();
                config.Add("ssl", "false");
                RedisObjectCache provider = new RedisObjectCache("test", config);

                DateTime utxExpiry = DateTime.UtcNow.AddSeconds(1);
                provider.Set("key10", "data10", utxExpiry, "testRegion");
                Assert.True(provider.Contains("key10", "testRegion"));
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        public void ExpiryTest()
        {
            using (new RedisServer())
            {
                NameValueCollection config = new NameValueCollection();
                config.Add("ssl", "false");
                RedisObjectCache provider = new RedisObjectCache("test", config);

                DateTime utxExpiry = DateTime.UtcNow.AddSeconds(1);
                provider.Set("key8", "data8", utxExpiry, "testRegion");
                // Wait for 1.1 seconds so that data will expire
                System.Threading.Thread.Sleep(1100);
                object data = provider.Get("key8", "testRegion");
                Assert.Equal(null, data);
            }
        }