Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,16 @@ public void WhenRemovedInWriteBuffer()
public void WhenItemDoesNotExistTryUpdateIsFalse()
{
cache.TryUpdate(1, 2).Should().BeFalse();
}

[Fact]
public void WhenAddingNullValueCanBeAddedAndRemoved()
{
// use foreground so that any null ref exceptions will surface
var lfu = new ConcurrentLfu<int, string>(1, 20, new ForegroundScheduler(), EqualityComparer<int>.Default);
lfu.GetOrAdd(1, _ => null).Should().BeNull();
lfu.AddOrUpdate(1, null);
lfu.TryRemove(1).Should().BeTrue();
}

[Fact]
Expand Down
7 changes: 7 additions & 0 deletions BitFaster.Caching.UnitTests/Lru/ConcurrentLruTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,13 @@ public void WhenValueExpiresItIsDisposed()
disposableValueFactory.Items[6].IsDisposed.Should().BeFalse();
}

[Fact]
public void WhenAddingNullValueCanBeAddedAndRemoved()
{
lru.GetOrAdd(1, _ => null).Should().BeNull();
lru.AddOrUpdate(1, null);
lru.TryRemove(1).Should().BeTrue();
}

[Fact]
public void WhenValueEvictedItemRemovedEventIsFired()
Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching/Lru/ConcurrentLruCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private void OnRemove(K key, I item)
this.telemetryPolicy.OnItemRemoved(key, item.Value, ItemRemovedReason.Removed);

// serialize dispose (common case dispose not thread safe)
lock (item.Value)
lock (item)
{
Disposer<V>.Dispose(item.Value);
}
Expand Down