public void CreateLRUCache_lockfree() { ILRUCache <SimpleLRUCacheItem, int> c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>(); Console.WriteLine("Created Empty Cache."); Assert.AreEqual(0, c.Count, 0, "Cache size is not zero"); c.Put(new SimpleLRUCacheItem(1, "Red")); Assert.AreEqual(1, c.Count, 0, "Cache size is not one"); c.Put(new SimpleLRUCacheItem(2, "Blue")); Assert.AreEqual(2, c.Count, 0, "Cache size is not two"); SimpleLRUCacheTests_lockfree.DumpCache(c, "Most Used/ Recently added to Least used/Oldest "); Console.WriteLine("lockfree Test Complete."); }
public void ExpirationTest1() { var c = new LRUCache_lockfree <SimpleLRUCacheItem, int, string>(10); c.Put(new SimpleLRUCacheItem(1, "Cat", new TimeSpan(0, 0, 5))); // 5 second timespan Assert.AreEqual(1, c.Count); Thread.Sleep(1 * 1000); // Sleep for 5 seconds. Assert.AreEqual(1, c.Count); Assert.AreEqual("Cat", c.Get(1).Value); Thread.Sleep(4 * 1000); // Sleep for 5 seconds. Assert.AreEqual(1, c.Count); Thread.Sleep(1 * 1000); // Sleep for 5 seconds. try { var val = c.Get(1); Assert.IsTrue(true, "Cat should no longer be present"); } catch { // Ignore } }