Exemple #1
0
        public void TestInitialize()
        {
            CacheManager.Settings = null;
            CacheManager.CacheManagerInternals = null;

            CacheManager.SetCache("cache*", new NoCache());

            cache1 = new Mocks.MockMemCache("cache1");
            CacheManager.SetCache(cache1.Name, cache1);

            cache2 = new Mocks.MockMemCache("cache2");
            CacheManager.SetCache(cache2.Name, cache2);

            cache3 = new Mocks.MockMemCache(typeof(TestProvider).FullName);
            CacheManager.SetCache(cache3.Name, cache3);

            cache4 = new Mocks.MockMemCache("mockCache*");
            CacheManager.SetCache(cache4.Name, cache4);

            this.cacheControllerUtil = new CacheControllerUtilExposed();
            this.cacheControllerUtil.ClearRegistrations();

            TestProvider.Hits1 = 0;
            TestProvider.Hits2 = 0;
        }
        public void TestLayeredCacheBothRegisteredToSameInstance1()
        {
            CacheManager.RemoveCache("l");
            CacheManager.RemoveCache("l*");
            CacheManager.RemoveCache("l1");
            CacheManager.RemoveCache("l2");

            var l = new Mocks.MockMemCache("l");

            CacheManager.SetCache("l1", l);
            CacheManager.SetCache("l2", l);

            var cache = new LayeredCache("cache0", "l1", "l2");
        }
 public void TestLayeredCacheLevelsEqual()
 {
     var l     = new Mocks.MockMemCache("l");
     var cache = new LayeredCache("cache0", l, l);
 }
        public void TestLayeredCacheValidInnerCaches()
        {
            var l1 = new Mocks.MockMemCache("l1");
            var l2 = new Mocks.MockMemCache("l2");

            var cache = new LayeredCache("cache0", l1, l2);

            int hits = 0;

            Func <int> getter = () => { hits++; return(hits); };

            int result;

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);
            Assert.AreEqual(2, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(0, l1.Hits);
            Assert.AreEqual(0, l2.Hits);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);
            Assert.AreEqual(2, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(1, l1.Hits);
            Assert.AreEqual(0, l2.Hits);

            l1.ClearAll(false);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);
            Assert.AreEqual(4, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(1, l1.Hits);
            Assert.AreEqual(1, l2.Hits);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);
            Assert.AreEqual(4, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(2, l1.Hits);
            Assert.AreEqual(1, l2.Hits);

            l2.ClearAll(false);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);
            Assert.AreEqual(4, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(3, l1.Hits);
            Assert.AreEqual(1, l2.Hits);

            result = cache.Get("key", getter);
            Assert.AreEqual(1, hits);
            Assert.AreEqual(1, result);
            Assert.AreEqual(4, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(4, l1.Hits);
            Assert.AreEqual(1, l2.Hits);

            l2.ClearAll(false);
            l1.ClearAll(false);

            result = cache.Get("key", getter);
            Assert.AreEqual(2, hits);
            Assert.AreEqual(2, result);
            Assert.AreEqual(6, l1.Misses);
            Assert.AreEqual(4, l2.Misses);
            Assert.AreEqual(4, l1.Hits);
            Assert.AreEqual(1, l2.Hits);

            result = cache.Get("key", getter);
            Assert.AreEqual(2, hits);
            Assert.AreEqual(2, result);
            Assert.AreEqual(6, l1.Misses);
            Assert.AreEqual(4, l2.Misses);
            Assert.AreEqual(5, l1.Hits);
            Assert.AreEqual(1, l2.Hits);

            // Clears counters too
            cache.ClearAll();

            result = cache.Get("key", getter);
            Assert.AreEqual(3, hits);
            Assert.AreEqual(3, result);
            Assert.AreEqual(2, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(0, l1.Hits);
            Assert.AreEqual(0, l2.Hits);

            result = cache.Get("key", getter);
            Assert.AreEqual(3, hits);
            Assert.AreEqual(3, result);
            Assert.AreEqual(2, l1.Misses);
            Assert.AreEqual(2, l2.Misses);
            Assert.AreEqual(1, l1.Hits);
            Assert.AreEqual(0, l2.Hits);
        }