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
9 changes: 9 additions & 0 deletions BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public void WhenItemIsAddedCountIsCorrect()
lru.Count.Should().Be(1);
}

[Fact]
public void WhenItemsAddedKeysContainsTheKeys()
{
lru.Count.Should().Be(0);
lru.GetOrAdd(1, valueFactory.Create);
lru.GetOrAdd(2, valueFactory.Create);
lru.Keys.Should().BeEquivalentTo(new[] { 1, 2 });
}

[Fact]
public void WhenItemExistsTryGetReturnsValueAndTrue()
{
Expand Down
9 changes: 9 additions & 0 deletions BitFaster.Caching.UnitTests/Lru/ConcurrentLruTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ public async Task WhenItemIsAddedCountIsCorrectAsync()
lru.Count.Should().Be(1);
}

[Fact]
public void WhenItemsAddedKeysContainsTheKeys()
{
lru.Count.Should().Be(0);
lru.GetOrAdd(1, valueFactory.Create);
lru.GetOrAdd(2, valueFactory.Create);
lru.Keys.Should().BeEquivalentTo(new[] { 1, 2 });
}

[Fact]
public void WhenItemExistsTryGetReturnsValueAndTrue()
{
Expand Down
8 changes: 8 additions & 0 deletions BitFaster.Caching/Lru/ClassicLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ public ClassicLru(int concurrencyLevel, int capacity, IEqualityComparer<K> compa

public int Count => this.linkedList.Count;

/// <summary>
/// Gets the ratio of hits to misses, where a value of 1 indicates 100% hits.
/// </summary>
public double HitRatio => (double)requestHitCount / (double)requestTotalCount;

/// <summary>
/// Gets a collection containing the keys in the cache.
/// </summary>
public ICollection<K> Keys => this.dictionary.Keys;

///<inheritdoc/>
public bool TryGet(K key, out V value)
{
Expand Down
5 changes: 5 additions & 0 deletions BitFaster.Caching/Lru/TemplateConcurrentLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public TemplateConcurrentLru(

public int ColdCount => this.coldCount;

/// <summary>
/// Gets a collection containing the keys in the cache.
/// </summary>
public ICollection<K> Keys => this.dictionary.Keys;

///<inheritdoc/>
public bool TryGet(K key, out V value)
{
Expand Down