Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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 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 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);
        }