public void OverwriteWithAbsoluteExpirationTest()
        {
            var key = "OverwriteWithAbsoluteExpirationTest";
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider();
            var result = cacheProvider.GetOrCreate <Guid>(key, () => val);

            Assert.AreEqual(result, val);

            var exist = cacheProvider.TryGet <Guid>(key, out val);

            Assert.IsTrue(exist);

            var val2 = Guid.NewGuid();

            cacheProvider.Overwrite <Guid>(key, val2, DateTime.UtcNow.AddSeconds(4D));

            Thread.Sleep(TimeSpan.FromSeconds(8D));
            Guid val3;

            exist = cacheProvider.TryGet <Guid>(key, out val3);
            Assert.IsFalse(exist);
            Assert.AreEqual(val3, Guid.Empty);
        }
Exemplo n.º 2
0
        public void OverwriteWithAbsoluteExpirationTest()
        {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider(ServiceStackRedis.Default);
            var t1 = DateTime.Now.AddSeconds(8D);
            var t2 = DateTime.UtcNow.AddSeconds(8D);

            Assert.AreEqual(t1.ToTimestamp(), t2.ToTimestamp());

            //DateTime.Now
            Guid result;

            cacheProvider.Overwrite(key, val, DateTime.Now.AddSeconds(8D));
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsTrue(exist);
                Assert.AreEqual(result, val);
            }
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsFalse(exist);
            }

            //DateTime.UtcNow
            cacheProvider.Overwrite(key, val, DateTime.UtcNow.AddSeconds(8D));
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsTrue(exist);
                Assert.AreEqual(result, val);
            }
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsFalse(exist);
            }
        }
        public void Save_null_then_get()
        {
            var            key   = "key-object-null";
            ICacheProvider cache = new RedisCacheProvider(
                ConfigurationManager.AppSettings.Get("cache:redis"), "region3");

            cache.Overwrite(key, (Person)null);
            Person id1;
            var    exists = cache.TryGet(key, out id1);

            Assert.IsTrue(exists);
        }
        public void OverwriteTest() {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider(new ServiceStackRedis());
            var result = cacheProvider.GetOrCreate<Guid>(key, () => val);
            Assert.AreEqual(result, val);

            var val2 = Guid.NewGuid();
            cacheProvider.Overwrite<Guid>(key, val2);

            Guid val3;
            var exist = cacheProvider.TryGet<Guid>(key, out val3);
            Assert.IsTrue(exist);
            Assert.AreEqual(val3, val2);
        }
        public void Set_then_expire()
        {
            var key   = Guid.NewGuid().ToString();
            var value = Guid.NewGuid();

            ICacheProvider cache = new RedisCacheProvider(
                ConfigurationManager.AppSettings.Get("cache:redis"), "region6");

            cache.Overwrite(key, value);

            cache.Expire(key);
            Guid value2;
            var  exist = cache.TryGet(key, out value2);

            Assert.IsFalse(exist);
            Assert.AreEqual(value2, Guid.Empty);
        }
        public void TryGetTest()
        {
            var  key = "TryGetTest";
            Guid val;

            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider();
            var exist = cacheProvider.TryGet <Guid>(key, out val);

            Assert.IsFalse(exist);
            Assert.AreEqual(val, Guid.Empty);

            var val2 = Guid.NewGuid();

            cacheProvider.Overwrite(key, val2);
            exist = cacheProvider.TryGet <Guid>(key, out val);
            Assert.IsTrue(exist);
            Assert.AreEqual(val, val2);
        }
Exemplo n.º 7
0
        public void OverwriteTest()
        {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider(ServiceStackRedis.Default);
            var result = cacheProvider.GetOrCreate <Guid>(key, () => val);

            Assert.AreEqual(result, val);

            var val2 = Guid.NewGuid();

            cacheProvider.Overwrite <Guid>(key, val2);

            Guid val3;
            var  exist = cacheProvider.TryGet <Guid>(key, out val3);

            Assert.IsTrue(exist);
            Assert.AreEqual(val3, val2);
        }
        public void OverwriteWithslidingExpirationTest() {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider(new ServiceStackRedis());

            //DateTime.Now
            Guid result;
            cacheProvider.Overwrite(key, val, TimeSpan.FromSeconds(8D));
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet<Guid>(key, out result);
                Assert.IsTrue(exist);
                Assert.AreEqual(result, val);
            }
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet<Guid>(key, out result);
                Assert.IsFalse(exist);
            }
        }
        public void OverwriteWithslidingExpirationTest()
        {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider(new ServiceStackRedis());

            //DateTime.Now
            Guid result;

            cacheProvider.Overwrite(key, val, TimeSpan.FromSeconds(8D));
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsTrue(exist);
                Assert.AreEqual(result, val);
            }
            {
                Thread.Sleep(TimeSpan.FromSeconds(5D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsFalse(exist);
            }
        }
Exemplo n.º 10
0
        public void Set_with_absoluteExpiration_then_get()
        {
            var key   = Guid.NewGuid().ToString();
            var value = Guid.NewGuid();

            ICacheProvider cache = new RedisCacheProvider(
                ConfigurationManager.AppSettings.Get("cache:redis"), "region5");

            cache.Overwrite(key, value, DateTime.Now.AddSeconds(3D));

            {
                Guid value2;
                Thread.Sleep(2000);
                var exist = cache.TryGet <Guid>(key, out value2);
                Assert.IsTrue(exist);
                Assert.AreEqual(value2, value);
            }
            {
                Guid value2;
                Thread.Sleep(2000);
                var exist = cache.TryGet(key, out value2);
                Assert.IsFalse(exist);
            }
        }
        public void Set_with_slidingExpiration_then_get()
        {
            var key   = "key-sliding-expiration";
            var value = Guid.NewGuid();

            ICacheProvider cache = new RedisCacheProvider(
                ConfigurationManager.AppSettings.Get("cache:redis"));

            cache.Overwrite(key, value, TimeSpan.FromSeconds(3D));

            {
                Guid value2;
                Thread.Sleep(2000);
                var exist = cache.TryGet <Guid>(key, out value2);
                Assert.IsTrue(exist);
                Assert.AreEqual(value2, value);
            }
            {
                Guid value2;
                Thread.Sleep(2000);
                var exist = cache.TryGet(key, out value2);
                Assert.IsFalse(exist);
            }
        }