Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 /// <summary>
 /// Should be called periodically to run cleanup tasks on data
 /// that has aged out
 /// </summary>
 public void Maintain()
 {
     _assetCache.Maintain();
     _bufferPool.Maintain();
 }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }