Exemple #1
0
        public void ExpireTest()
        {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IRedis redis = ServiceStackRedis.Default;
            IHttpRuntimeCacheProvider cacheProvider = new RedisCacheProvider(redis);

            {
                var result = cacheProvider.GetOrCreate <Guid>(key, () => val);
                Assert.AreEqual(result, val);

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

                cacheProvider.Expire(key);
                Guid val2;
                exist = cacheProvider.TryGet <Guid>(key, out val2);
                Assert.IsFalse(exist);
                Assert.AreEqual(val2, Guid.Empty);
            }


            {
                var result = cacheProvider.GetOrCreate <Guid>(key, () => val);
                Assert.AreEqual(result, val);

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

                cacheProvider.Expire(key);
                Guid val2;
                exist = cacheProvider.TryGet <Guid>(key, out val2);
                Assert.IsFalse(exist);
                Assert.AreEqual(val2, Guid.Empty);
            }
        }
        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 Save_ReferenceType_then_get()
        {
            var            key   = "key-object";
            ICacheProvider cache = new RedisCacheProvider(
                ConfigurationManager.AppSettings.Get("cache:redis"), "region2");
            var id1 = new Object();
            var id2 = cache.GetOrCreate(key, _ => id1);

            Assert.AreEqual(id1, id2);

            cache.Expire(key);
            Object id3;
            var    exists = cache.TryGet(key, out id3);

            Assert.IsFalse(exists);
            Assert.AreNotEqual(id1, id3);
            Assert.AreEqual(id3, null);
        }
        public void Save_ValueType_then_get()
        {
            var            key   = "key-guid";
            ICacheProvider cache = new RedisCacheProvider(
                ConfigurationManager.AppSettings.Get("cache:redis"), "region1");
            var id1 = Guid.NewGuid();
            var id2 = cache.GetOrCreate(key, _ => id1);

            Assert.AreEqual(id1, id2);

            cache.Expire(key);
            Guid id3;
            var  exists = cache.TryGet(key, out id3);

            Assert.IsFalse(exists);
            Assert.AreNotEqual(id1, id3);
            Assert.AreEqual(id3, Guid.Empty);
        }
        public void ExpireTest()
        {
            var key = "ExpireTest";
            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);

            cacheProvider.Expire(key);
            Guid val2;

            exist = cacheProvider.TryGet <Guid>(key, out val2);
            Assert.IsFalse(exist);
            Assert.AreEqual(val2, Guid.Empty);
        }
        public void ExpireTest() {
            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 exist = cacheProvider.TryGet<Guid>(key, out val);
            Assert.IsTrue(exist);

            cacheProvider.Expire(key);
            Guid val2;
            exist = cacheProvider.TryGet<Guid>(key, out val2);
            Assert.IsFalse(exist);
            Assert.AreEqual(val2, Guid.Empty);
        }