public void CombinedTest() { var cache = new WeakestCache <Item, Item>(false, false, i => i); item1 = new Item("1"); cache.Add(item1); Assert.AreSame(item1, cache.First()); Assert.AreSame(item1, cache[new Item("1"), true]); cache.Remove(item1); Assert.AreEqual(0, cache.Count); cache.Add(item1); TestHelper.CollectGarbage(true); cache.CollectGarbage(); Assert.AreEqual(1, cache.Count); item1 = null; TestHelper.CollectGarbage(true); cache.CollectGarbage(); Assert.AreEqual(0, cache.Count); Assert.IsNull(cache[new Item("1"), true]); }
public void ProfileTest() { var cache = new WeakestCache <Item, Item>(false, false, i => i); var measurement = new Measurement(); for (int i = 0, j = 0; i < 1000000; i++, j++) { var item = new Item(i.ToString()); cache.Add(item); if (j == 100000) { j = 0; Console.Out.WriteLine(measurement.ToString()); } } }