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"); }
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"); }
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"); }