Skip to content

Commit c452ae4

Browse files
authored
props (#121)
1 parent 8995ef2 commit c452ae4

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public void ConstructAddAndRetrieveWithDefaultCtorReturnsValue()
4949
x.GetOrAdd(1, k => k).Should().Be(1);
5050
}
5151

52+
[Fact]
53+
public void WhenCtorCapacityArgIs3CapacityIs3()
54+
{
55+
new ClassicLru<int, int>(3).Capacity.Should().Be(3);
56+
}
57+
5258
[Fact]
5359
public void WhenItemIsAddedCountIsCorrect()
5460
{

BitFaster.Caching.UnitTests/Lru/ConcurrentLruTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void WhenCapacityIs4HotHasCapacity1AndColdHasCapacity2()
6969

7070
lru.HotCount.Should().Be(1);
7171
lru.ColdCount.Should().Be(2);
72+
lru.Capacity.Should().Be(4);
7273
}
7374

7475
[Fact]
@@ -83,6 +84,7 @@ public void WhenCapacityIs5HotHasCapacity2AndColdHasCapacity2()
8384

8485
lru.HotCount.Should().Be(2);
8586
lru.ColdCount.Should().Be(2);
87+
lru.Capacity.Should().Be(5);
8688
}
8789

8890
[Fact]

BitFaster.Caching/ICache.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ namespace BitFaster.Caching
1313
/// <typeparam name="V">The type of values in the cache.</typeparam>
1414
public interface ICache<K, V>
1515
{
16+
/// <summary>
17+
/// Gets the total number of items that can be stored in the cache.
18+
/// </summary>
19+
int Capacity { get; }
20+
21+
/// <summary>
22+
/// Gets the number of items currently held in the cache.
23+
/// </summary>
24+
int Count { get; }
25+
1626
/// <summary>
1727
/// Attempts to get the value associated with the specified key from the cache.
1828
/// </summary>

BitFaster.Caching/Lru/ClassicLru.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ public ClassicLru(int concurrencyLevel, int capacity, IEqualityComparer<K> compa
4848
this.dictionary = new ConcurrentDictionary<K, LinkedListNode<LruItem>>(concurrencyLevel, this.capacity + 1, comparer);
4949
}
5050

51+
///<inheritdoc/>
5152
public int Count => this.linkedList.Count;
5253

54+
///<inheritdoc/>
55+
public int Capacity => this.capacity;
56+
5357
/// <summary>
5458
/// Gets the ratio of hits to misses, where a value of 1 indicates 100% hits.
5559
/// </summary>

BitFaster.Caching/Lru/TemplateConcurrentLru.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ public TemplateConcurrentLru(
8989
}
9090

9191
// No lock count: https://arbel.net/2013/02/03/best-practices-for-using-concurrentdictionary/
92+
///<inheritdoc/>
9293
public int Count => this.dictionary.Skip(0).Count();
9394

95+
///<inheritdoc/>
96+
public int Capacity => this.coldCapacity + this.warmCapacity + this.hotCapacity;
97+
9498
public int HotCount => this.hotCount;
9599

96100
public int WarmCount => this.warmCount;

0 commit comments

Comments
 (0)