public void TestAgingRemovesEntriesButPreservesReservedEntries() { var cache = new LRUCache <UUID, String>(10, minSize: 1, maxAge: 1000); UUID firstEntryId = UUID.Random(); String firstEntryData = "First Entry"; cache.Add(firstEntryId, firstEntryData); UUID secondEntryId = UUID.Random(); String secondEntryData = "Second Entry"; cache.Add(secondEntryId, secondEntryData); Thread.Sleep(5 * 1000); cache.Maintain(); Assert.AreEqual(1, cache.Count); Assert.AreEqual(1, cache.Size); String lastInsertedValue; Assert.IsFalse(cache.TryGetValue(firstEntryId, out lastInsertedValue)); Assert.IsNull(lastInsertedValue); Assert.IsTrue(cache.TryGetValue(secondEntryId, out lastInsertedValue)); Assert.AreEqual(secondEntryData, lastInsertedValue); }
public void TestAgingRemovesEntriesUsingBytesForReservedSize() { UUID firstEntryId = UUID.Random(); String firstEntryData = "First Entry"; UUID secondEntryId = UUID.Random(); String secondEntryData = "Second Entry"; var cache = new LRUCache <UUID, String>(capacity: 250, useSizing: true, minSize: secondEntryData.Length, maxAge: 1000); cache.Add(firstEntryId, firstEntryData, firstEntryData.Length); cache.Add(secondEntryId, secondEntryData, secondEntryData.Length); Thread.Sleep(5 * 1000); cache.Maintain(); Assert.AreEqual(1, cache.Count); Assert.AreEqual(secondEntryData.Length, cache.Size); String lastInsertedValue; Assert.IsFalse(cache.TryGetValue(firstEntryId, out lastInsertedValue)); Assert.IsNull(lastInsertedValue); Assert.IsTrue(cache.TryGetValue(secondEntryId, out lastInsertedValue)); Assert.AreEqual(secondEntryData, lastInsertedValue); }
public void TestAgingRemovesEntriesPastExpirationInterval() { var cache = new LRUCache <UUID, string>(10, maxAge: 1000); UUID firstEntryId = UUID.Random(); string firstEntryData = "First Entry"; cache.Add(firstEntryId, firstEntryData); Thread.Sleep(2 * 1000); cache.Maintain(); Assert.AreEqual(0, cache.Count, "Count property was wrong"); Assert.AreEqual(0, cache.Size, "Size property was wrong"); Assert.IsFalse(cache.TryGetValue(firstEntryId, out string lastInsertedValue)); Assert.IsNull(lastInsertedValue); }
/// <summary> /// Should be called periodically to run cleanup tasks on data /// that has aged out /// </summary> public void Maintain() { _assetCache.Maintain(); _bufferPool.Maintain(); }
public void TestAgingRemovesEntriesUsingBytesForReservedSize() { UUID firstEntryId = UUID.Random(); String firstEntryData = "First Entry"; UUID secondEntryId = UUID.Random(); String secondEntryData = "Second Entry"; var cache = new LRUCache<UUID, String>(capacity: 250, useSizing: true, minSize: secondEntryData.Length, maxAge: 1000); cache.Add(firstEntryId, firstEntryData, firstEntryData.Length); cache.Add(secondEntryId, secondEntryData, secondEntryData.Length); Thread.Sleep(5 * 1000); cache.Maintain(); Assert.AreEqual(1, cache.Count); Assert.AreEqual(secondEntryData.Length, cache.Size); String lastInsertedValue; Assert.IsFalse(cache.TryGetValue(firstEntryId, out lastInsertedValue)); Assert.IsNull(lastInsertedValue); Assert.IsTrue(cache.TryGetValue(secondEntryId, out lastInsertedValue)); Assert.AreEqual(secondEntryData, lastInsertedValue); }
public void TestAgingRemovesEntriesButPreservesReservedEntries() { var cache = new LRUCache<UUID, String>(10, minSize : 1, maxAge : 1000); UUID firstEntryId = UUID.Random(); String firstEntryData = "First Entry"; cache.Add(firstEntryId, firstEntryData); UUID secondEntryId = UUID.Random(); String secondEntryData = "Second Entry"; cache.Add(secondEntryId, secondEntryData); Thread.Sleep(5 * 1000); cache.Maintain(); Assert.AreEqual(1, cache.Count); Assert.AreEqual(1, cache.Size); String lastInsertedValue; Assert.IsFalse(cache.TryGetValue(firstEntryId, out lastInsertedValue)); Assert.IsNull(lastInsertedValue); Assert.IsTrue(cache.TryGetValue(secondEntryId, out lastInsertedValue)); Assert.AreEqual(secondEntryData, lastInsertedValue); }
public void TestAgingRemovesEntriesPastExpirationInterval() { var cache = new LRUCache<UUID, String>(10, maxAge : 1000); UUID firstEntryId = UUID.Random(); String firstEntryData = "First Entry"; cache.Add(firstEntryId, firstEntryData); Thread.Sleep(2 * 1000); cache.Maintain(); Assert.AreEqual(0, cache.Count); Assert.AreEqual(0, cache.Size); String lastInsertedValue; Assert.IsFalse(cache.TryGetValue(firstEntryId, out lastInsertedValue)); Assert.IsNull(lastInsertedValue); }