示例#1
0
        public void TestCacheSomeItemsAccessedJustBeforeGC()
        {
            Cache cache = new Cache();
            for (int i = 0; i < 5; i++)
            {
                cache.Add(i, new byte[1024]);
            }

            var value1 = cache[1];
            var value3 = cache[3];

            Assert.AreEqual(5, cache.Count);
            Assert.AreEqual(5, cache.ActiveCount);
            Assert.IsNotNull(cache[0]);
            Assert.IsNotNull(cache[1]);
            Assert.IsNotNull(cache[2]);
            Assert.IsNotNull(cache[3]);
            Assert.IsNotNull(cache[4]);

            GC.Collect();

            Assert.AreEqual(5, cache.Count);
            Assert.AreEqual(2, cache.ActiveCount);
            Assert.IsNull(cache[0]);
            Assert.IsNotNull(cache[1]);
            Assert.IsNull(cache[2]);
            Assert.IsNotNull(cache[3]);
            Assert.IsNull(cache[4]);
        }
示例#2
0
        public void TestCacheAllItemsAccessedJustBeforeGC()
        {
            Cache cache = new Cache();
            for (int i = 0; i < 4; i++)
            {
                cache.Add(i, new DummyClass { Name = i.ToString(), Value = new byte[1024] });
            }

            var value0 = cache[0];
            var value1 = cache[1];
            var value2 = cache[2];
            var value3 = cache[3];

            Assert.AreEqual(4, cache.Count);
            Assert.AreEqual(4, cache.ActiveCount);
            Assert.AreEqual("0", (cache[0] as DummyClass).Name);
            Assert.AreEqual("1", (cache[1] as DummyClass).Name);
            Assert.AreEqual("2", (cache[2] as DummyClass).Name);
            Assert.AreEqual("3", (cache[3] as DummyClass).Name);

            GC.Collect();

            Assert.AreEqual(4, cache.Count);
            Assert.AreEqual(4, cache.ActiveCount);
            Assert.AreEqual("0", (cache[0] as DummyClass).Name);
            Assert.AreEqual("1", (cache[1] as DummyClass).Name);
            Assert.AreEqual("2", (cache[2] as DummyClass).Name);
            Assert.AreEqual("3", (cache[3] as DummyClass).Name);
        }
示例#3
0
        public void TestCacheNoItemsAccessedBeforeGC()
        {
            Cache cache = new Cache();
            for (int i = 0; i < 5; i++)
            {
                cache.Add(i, i.ToString());
            }

            Assert.AreEqual(5, cache.Count);
            Assert.AreEqual(5, cache.ActiveCount);
            Assert.AreEqual("0", cache[0]);
            Assert.AreEqual("1", cache[1]);
            Assert.AreEqual("2", cache[2]);
            Assert.AreEqual("3", cache[3]);
            Assert.AreEqual("4", cache[4]);

            GC.Collect();

            Assert.AreEqual(5, cache.Count);
            Assert.AreEqual(0, cache.ActiveCount);
            Assert.IsNull(cache[0]);
            Assert.IsNull(cache[1]);
            Assert.IsNull(cache[2]);
            Assert.IsNull(cache[3]);
            Assert.IsNull(cache[4]);
        }
示例#4
0
文件: Cache.cs 项目: loysset/retos
 public CacheDebugView(Cache cache)
 {
     this.cache = cache;
 }