public void SetAlwaysOverwrites()
        {
            var cache  = RedisTestConfig.CreateCacheInstance(GetType().Name);
            var value1 = new byte[1] {
                1
            };
            string key = "myKey";

            cache.Set(key, value1);
            var result = cache.Get(key);

            Assert.Equal(value1, result);

            var value2 = new byte[1] {
                2
            };

            cache.Set(key, value2);
            result = cache.Get(key);
            Assert.Equal(value2, result);
        }
예제 #2
0
        public void SlidingExpirationRenewedByAccess()
        {
            var cache = RedisTestConfig.CreateCacheInstance(GetType().Name);
            var key   = "myKey";
            var value = new byte[1];

            cache.Set(key, value, new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromSeconds(1)));

            var result = cache.Get(key);

            Assert.Equal(value, result);

            for (int i = 0; i < 5; i++)
            {
                Thread.Sleep(TimeSpan.FromSeconds(0.5));

                result = cache.Get(key);
                Assert.Equal(value, result);
            }

            Thread.Sleep(TimeSpan.FromSeconds(3));
            result = cache.Get(key);
            Assert.Null(result);
        }