コード例 #1
0
        public ScavengedExpirableCacheStore(CacheOptions cacheOptions)
        {
            Guard.Assert(cacheOptions.MaxCacheItemCount > 0, "invalid cache item count");
            Guard.Assert(cacheOptions.ScavengePercentage > 0, "invalid scavenge percentage");

            _CacheOptions = cacheOptions;
            _ExpirableCacheStore = new ExpirableCacheStore(_CacheOptions);
        }
コード例 #2
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");
        }
コード例 #3
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");
        }
コード例 #4
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");
        }
コード例 #5
0
        public void TestExpirationPolling()
        {
            ExpirableCacheStore expirableCacheStore = new ExpirableCacheStore(new CacheOptions { ExpirationPollInterval = TimeSpan.FromSeconds(1) });

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

            Assert.AreEqual(expirableCacheStore.CacheItemCount, 1, "count mismatch");

            Thread.Sleep(1100);
            Assert.AreEqual(expirableCacheStore.CacheItemCount, 1, "count mismatch");

            ((TestExpirationSpecifier)cacheItem.ExpirationSpecifierList[0]).Expired = true;
            Thread.Sleep(1100);
            Assert.AreEqual(expirableCacheStore.CacheItemCount, 0, "count mismatch");
        }