public void EvictionHonorsLruFromPreviousSession() { Set("a", "a", "a"); Set("b", "b", "b"); Set("c", "c", "c"); Set("d", "d", "d"); Set("e", "e", "e"); Set("f", "f", "f"); cache.Get("b").Dispose(); // 'B' is now least recently used. Assert.That(cache.Size, Is.EqualTo(12)); cache.Flush(); cache = DiskLruCache.Open(directory, AppVersion, 2, 10); Set("g", "g", "g"); cache.Flush(); Assert.That(cache.Size, Is.EqualTo(10)); AssertAbsent("a"); AssertValue("b", "b", "b"); AssertAbsent("c"); AssertValue("d", "d", "d"); AssertValue("e", "e", "e"); AssertValue("f", "f", "f"); AssertValue("g", "g", "g"); }
public void EvictionHonorsLruFromCurrentSession() { cache.Dispose(); cache = DiskLruCache.Open(directory, AppVersion, 2, 10); Set("a", "a", "a"); Set("b", "b", "b"); Set("c", "c", "c"); Set("d", "d", "d"); Set("e", "e", "e"); cache.Get("b").Dispose(); // 'B' is now least recently used. // Causing the size to grow to 12 should evict 'A'. Set("f", "f", "f"); // Causing the size to grow to 12 should evict 'C'. Set("g", "g", "g"); cache.Flush(); Assert.That(cache.Size, Is.EqualTo(10)); AssertAbsent("a"); AssertValue("b", "b", "b"); AssertAbsent("c"); AssertValue("d", "d", "d"); AssertValue("e", "e", "e"); AssertValue("f", "f", "f"); }
public void CacheSingleValueOfSizeGreaterThanMaxSize() { cache.Dispose(); cache = DiskLruCache.Open(directory, AppVersion, 2, 10); Set("a", "aaaaaaaaaaa", "a"); // size=12 cache.Flush(); AssertAbsent("a"); }
public void EditSinceEvicted() { cache.Dispose(); cache = DiskLruCache.Open(directory, AppVersion, 2, 10); Set("a", "aa", "aaa"); // size 5 var snapshot = cache.Get("a"); Set("b", "bb", "bbb"); // size 5 Set("c", "cc", "ccc"); // size 5; will evict 'A' cache.Flush(); Assert.That(snapshot.Edit(), Is.Null); }
public void EvictOnInsert() { cache.Dispose(); cache = DiskLruCache.Open(directory, AppVersion, 2, 10); Set("a", "a", "aaa"); // size 4 Set("b", "bb", "bbbb"); // size 6 Assert.That(cache.Size, Is.EqualTo(10)); // Cause the size to grow to 12 should evict 'A'. Set("c", "c", "c"); cache.Flush(); Assert.That(cache.Size, Is.EqualTo(8)); AssertAbsent("a"); AssertValue("b", "bb", "bbbb"); AssertValue("c", "c", "c"); // Causing the size to grow to 10 should evict nothing. Set("d", "d", "d"); cache.Flush(); Assert.That(cache.Size, Is.EqualTo(10)); AssertAbsent("a"); AssertValue("b", "bb", "bbbb"); AssertValue("c", "c", "c"); AssertValue("d", "d", "d"); // Causing the size to grow to 18 should evict 'B' and 'C'. Set("e", "eeee", "eeee"); cache.Flush(); Assert.That(cache.Size, Is.EqualTo(10)); AssertAbsent("a"); AssertAbsent("b"); AssertAbsent("c"); AssertValue("d", "d", "d"); AssertValue("e", "eeee", "eeee"); }
public void EvictOnUpdate() { cache.Dispose(); cache = DiskLruCache.Open(directory, AppVersion, 2, 10); Set("a", "a", "aa"); // size 3 Set("b", "b", "bb"); // size 3 Set("c", "c", "cc"); // size 3 Assert.That(cache.Size, Is.EqualTo(9)); // Causing the size to grow to 11 should evict 'A'. Set("b", "b", "bbbb"); cache.Flush(); Assert.That(cache.Size, Is.EqualTo(8)); AssertAbsent("a"); AssertValue("b", "b", "bbbb"); AssertValue("c", "c", "cc"); }