public void ClearsWhenLarge() { var dict = new SimpleLruDictionary <object, object>(10, TimeSpan.FromMilliseconds(100)); for (int i = 0; i < 25; i++) { dict.GetOrCreate(i, _ => i); } GC.Collect(2, GCCollectionMode.Forced); Assert.IsTrue(dict.TryGetValue(24, out _)); Assert.IsFalse(dict.TryGetValue(1, out _)); }
public void ClearsOnTimeout() { var dict = new SimpleLruDictionary <object, object>(10, TimeSpan.FromMilliseconds(1)); for (int i = 0; i < 20; i++) { dict.GetOrCreate(i, _ => new object()); } Thread.Sleep(30); // let's give the timer some margin so this test does not fail randomly GC.Collect(2, GCCollectionMode.Forced); Assert.IsFalse(dict.TryGetValue(1, out _)); }