コード例 #1
0
        public void TestCustomExpiration()
        {
            ExpirableCacheStore expirableCacheStore = new ExpirableCacheStore(new CacheOptions());

            CacheItem cacheItem = new CacheItem("cacheItem", null, 0, new IExpirationSpecifier[] { new TestExpirationSpecifier() });
            expirableCacheStore.Set(cacheItem);

            Assert.IsTrue(Object.ReferenceEquals(cacheItem, expirableCacheStore.Get(cacheItem.Key, false)), "unable to get object");

            ((TestExpirationSpecifier)cacheItem.ExpirationSpecifierList[0]).Expired = true;
            Assert.IsNull(expirableCacheStore.Get(cacheItem.Key, false), "unable to expire object");
        }
コード例 #2
0
        public void TestAbsoluteExpiration()
        {
            ExpirableCacheStore expirableCacheStore = new ExpirableCacheStore(new CacheOptions());

            CacheItem cacheItem = new CacheItem("cacheItem", null, 0, new IExpirationSpecifier[] { new AbsoluteTimeExpirationSpecifier(DateTime.UtcNow.AddSeconds(1)) });
            expirableCacheStore.Set(cacheItem);

            Assert.IsTrue(Object.ReferenceEquals(cacheItem, expirableCacheStore.Get(cacheItem.Key, false)), "unable to get object");
            Thread.Sleep(300);
            Assert.IsTrue(Object.ReferenceEquals(cacheItem, expirableCacheStore.Get(cacheItem.Key, false)), "unable to get object");
            Thread.Sleep(900);
            Assert.IsNull(expirableCacheStore.Get(cacheItem.Key, false), "unable to expire object");
        }
コード例 #3
0
        public void TestSlidingExpiration()
        {
            ExpirableCacheStore expirableCacheStore = new ExpirableCacheStore(new CacheOptions());

            CacheItem cacheItem = new CacheItem("cacheItem", null, 0, new IExpirationSpecifier[] { new SlidingWindowExpirationSpecifier(TimeSpan.FromSeconds(1)) });
            expirableCacheStore.Set(cacheItem);

            Assert.IsTrue(Object.ReferenceEquals(cacheItem, expirableCacheStore.Get(cacheItem.Key, false)), "unable to get object");
            Thread.Sleep(300);
            Assert.IsTrue(Object.ReferenceEquals(cacheItem, expirableCacheStore.Get(cacheItem.Key, false)), "unable to get object");
            Thread.Sleep(900);
            Assert.IsTrue(Object.ReferenceEquals(cacheItem, expirableCacheStore.Get(cacheItem.Key, false)), "unable to get object");
            Thread.Sleep(1100);
            Assert.IsNull(expirableCacheStore.Get(cacheItem.Key, false), "unable to expire object");
        }