public void Test() { TimeBasedCache <int, int> tbc = new TimeBasedCache <int, int>(600000); tbc.EvictionHandler += HandleEviction; int val = 0; bool update = false; Assert.IsFalse(tbc.TryGetValue(10, out val, out update), "Empty"); Assert.IsFalse(update, "Empty -- update"); tbc.Update(10, 5); Assert.IsTrue(tbc.TryGetValue(10, out val, out update), "First"); Assert.IsFalse(update, "First -- update"); Assert.AreEqual(5, val); tbc.Recycle(DateTime.UtcNow); Assert.IsTrue(tbc.TryGetValue(10, out val, out update), "Second"); Assert.IsTrue(update, "Second -- update"); Assert.AreEqual(5, val); tbc.Recycle(DateTime.UtcNow); Assert.IsFalse(tbc.TryGetValue(10, out val, out update), "Recycled"); Assert.IsFalse(update, "Recycled -- update"); Assert.AreEqual(10, _last_ea.Key, "Key"); Assert.AreEqual(5, _last_ea.Value, "Value"); tbc.Stop(); }
protected void HandleEviction(object sender, TimeBasedCache <int, int> .EvictionArgs ea) { _last_ea = ea; }