public void Show(LibraryViewNode node) { try { if (node is LibraryFileNode) { using (var guard = new MultiGuard(1)) { IClaim newBinary; guard.Accept(newBinary = _binariesCache.GetBinary(node.Id)); if (newBinary != null) { ChangeClaim(newBinary); guard.Commit(); LoadImage(newBinary.Binary); } } } else { Image = null; } } // ReSharper disable once EmptyGeneralCatchClause catch { } }
public void ExcessItemsAreRemovedFromCacheWhenClaimsAreReleased() { using (var mg = new MultiGuard()) { _items.Take(10).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList(); } Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity)); }
public void CacheBecomesOversizedIfClaimsExceedCapacity() { using (var mg = new MultiGuard()) { var claims = _items.Take(10).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList(); Assert.That(_cache.NumItems, Is.EqualTo(claims.Count)); } }
public void UnclaimedItemsAreDiscardedToMakeRoomForNewClaims() { using (var mg = new MultiGuard()) { _items.Take(CacheCapacity).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList(); } //cache is now full of unclaimed items. In order to load the last one, an old one needs to be discarded. using (_cache.GetBinary(_items.Last().Id)) Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity)); }
public void TwoClaimsCreateAClaimCountOfTwo() { using (var mg = new MultiGuard()) { _items.Take(CacheCapacity).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList(); var guid = _items.Last().Id; using (_cache.GetBinary(guid)) { //cache is now oversize - claim and release the same item again. the cache should stay oversized using (_cache.GetBinary(guid)) { } Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity + 1)); } } }
public void ItemsAreReleasedWhenAllClaimsAreDisposed() { using (var mg = new MultiGuard()) { _items.Take(CacheCapacity).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList(); var guid = _items.Last().Id; using (_cache.GetBinary(guid)) { //cache is now oversize - claim and release the same item again. the cache should stay oversized using (_cache.GetBinary(guid)) { } } //cache should now be full (there are still enough claims to keep it full, so the only one released will be the double claimed one) Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity)); } }