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