public void OverwriteWithslidingExpirationTest()
        {
            var key = Guid.NewGuid().ToString("n");

            key = "ecc6cf4d923f48b3a98f11b9641549fd";
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();

            cacheProvider.Overwrite(key, val, TimeSpan.FromSeconds(6D));

            Guid result;

            for (var i = 0; i < 2; i++)
            {
                Thread.Sleep(TimeSpan.FromSeconds(4D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsTrue(exist);
                Assert.AreEqual(result, val);
            }

            {
                Thread.Sleep(TimeSpan.FromSeconds(8D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsFalse(exist);
            }
        }
示例#2
0
        public void Set_with_slidingExpiration_then_get()
        {
            var key   = Guid.NewGuid().ToString();
            var value = Guid.NewGuid();

            ICacheProvider cache = new MemcachedCacheProvider("enyim.com/memcached", "region4");

            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.IsTrue(exist);
                Assert.AreEqual(value2, value);
            }
            {
                Guid value2;
                Thread.Sleep(4000);
                var exist = cache.TryGet(key, out value2);
                Assert.IsFalse(exist);
            }
        }
        public void OverwriteWithAbsoluteExpirationTest()
        {
            var key = Guid.NewGuid().ToString("n");
            //key = "73218975a30d49ba9cd347bc1b62470a";
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();
            var t1 = DateTime.Now.AddSeconds(5D).ToTimestamp();
            var t2 = DateTime.UtcNow.AddSeconds(5D).ToTimestamp();

            Assert.AreEqual(t1, t2);

            cacheProvider.Overwrite(key, val, DateTime.Now.AddSeconds(6D));
            Guid result = Guid.NewGuid();

            {
                Thread.Sleep(TimeSpan.FromSeconds(4D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsTrue(exist);
                Assert.AreEqual(result, val);
            }

            {
                Thread.Sleep(TimeSpan.FromSeconds(8D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsFalse(exist);
            }
        }
示例#4
0
        public void Save_null_then_get()
        {
            var            key   = "key-object-null";
            ICacheProvider cache = new MemcachedCacheProvider("enyim.com/memcached", "region3");

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

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

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();
            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 OverwriteWithslidingExpirationTest() {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();

            //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 GetOrCreateWithAbsoluteExpirationTest()
        {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();
            var result = cacheProvider.GetOrCreate <Guid>(key, () => val, DateTime.UtcNow.AddSeconds(6D));

            Assert.AreEqual(result, val);

            {
                Thread.Sleep(TimeSpan.FromSeconds(4D));
                var exist = cacheProvider.TryGet <Guid>(key, out result);
                Assert.IsTrue(exist);
                Assert.AreEqual(result, val);
            }

            {
                Thread.Sleep(TimeSpan.FromSeconds(8D));
                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 MemcachedCacheProvider();

            //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 OverwriteTest() {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();
            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);
        }
示例#10
0
        public void Set_then_expire()
        {
            var key   = Guid.NewGuid().ToString();
            var value = Guid.NewGuid();

            ICacheProvider cache = new MemcachedCacheProvider("enyim.com/memcached", "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);
        }
示例#11
0
        public void Save_ReferenceType_then_get()
        {
            var            key   = "key-object";
            ICacheProvider cache = new MemcachedCacheProvider("enyim.com/memcached", "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);
        }
示例#12
0
        public void Save_ValueType_then_get()
        {
            var            key   = "key-guid";
            ICacheProvider cache = new MemcachedCacheProvider("enyim.com/memcached", "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 OverwriteTest()
        {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();
            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);
        }
示例#14
0
        public void Compatibility2()
        {
            var cache  = new MemcachedCacheProvider("Test");
            var person = new Person {
                Id      = 2,
                Name    = "Rattz",
                Address = new Address {
                    Line1 = "Haidin Shuzhoujie",
                    Line2 = "Beijing China"
                }
            };

            var key = "Person";

            cache.Overwrite(key, person, TimeSpan.FromHours(1D));
            Person personOut;
            var    exist = cache.TryGet <Person>(key, out personOut);

            Assert.IsTrue(exist);
            Assert.IsNotNull(personOut);
        }
        public void GetOrCreateTest() {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

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

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

            {
                var result2 = cacheProvider.GetOrCreate<Guid>(key, () => {
                    Assert.Fail();
                    return Guid.NewGuid();
                });
                Assert.AreEqual(result2, val);
            }
        }
        public void GetOrCreateTest()
        {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

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

            Assert.AreEqual(result, val);

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

            {
                var result2 = cacheProvider.GetOrCreate <Guid>(key, () => {
                    Assert.Fail();
                    return(Guid.NewGuid());
                });
                Assert.AreEqual(result2, val);
            }
        }
        public void ExpireTest() {
            var key = Guid.NewGuid().ToString("n");
            var val = Guid.NewGuid();

            IHttpRuntimeCacheProvider cacheProvider = new MemcachedCacheProvider();
            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);
        }
示例#18
0
        public void Compatibility2() {
            var cache = new MemcachedCacheProvider("Test");
            var person = new Person {
                Id = 2,
                Name = "Rattz",
                Address = new Address {
                    Line1 = "Haidin Shuzhoujie",
                    Line2 = "Beijing China"
                }
            };

            var key = "Person";
            cache.Overwrite(key, person, TimeSpan.FromHours(1D));
            Person personOut;
            var exist = cache.TryGet<Person>(key, out personOut);
            Assert.IsTrue(exist);
            Assert.IsNotNull(personOut);
        }