Skip to content

Commit 8934324

Browse files
authored
Add missing key not null constraints (#594)
1 parent 5483cbf commit 8934324

21 files changed

+22
-0
lines changed

BitFaster.Caching/CacheDebugView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace BitFaster.Caching
66
{
77
[ExcludeFromCodeCoverage]
88
internal class CacheDebugView<K, V>
9+
where K : notnull
910
{
1011
private readonly ICache<K, V> cache;
1112

BitFaster.Caching/Lfu/Builder/LfuBuilderBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace BitFaster.Caching.Lfu.Builder
1212
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
1313
/// <typeparam name="TCacheReturn">The return type of the builder.</typeparam>
1414
public abstract class LfuBuilderBase<K, V, TBuilder, TCacheReturn> where TBuilder : LfuBuilderBase<K, V, TBuilder, TCacheReturn>
15+
where K : notnull
1516
{
1617
internal readonly LfuInfo<K> info;
1718

BitFaster.Caching/Lfu/Builder/LfuInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace BitFaster.Caching.Lfu.Builder
88
{
99
internal sealed class LfuInfo<K>
10+
where K : notnull
1011
{
1112
private object? expiry = null;
1213

BitFaster.Caching/Lfu/LfuNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace BitFaster.Caching.Lfu
33
{
44
internal class LfuNode<K, V>
5+
where K : notnull
56
{
67
internal LfuNodeList<K, V> list;
78
internal LfuNode<K, V> next;
@@ -66,6 +67,7 @@ internal enum Position
6667
}
6768

6869
internal sealed class AccessOrderNode<K, V> : LfuNode<K, V>
70+
where K : notnull
6971
{
7072
public AccessOrderNode(K k, V v) : base(k, v)
7173
{

BitFaster.Caching/Lru/AfterAccessPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
77
/// Implement an expire after access policy.
88
/// </summary>
99
internal readonly struct AfterAccessPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
10+
where K : notnull
1011
{
1112
private readonly Duration timeToLive;
1213
private readonly Time time;

BitFaster.Caching/Lru/Builder/LruBuilderBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru.Builder
77
/// Recursive generic base class enables builder inheritance.
88
/// </summary>
99
public abstract class LruBuilderBase<K, V, TBuilder, TCacheReturn> where TBuilder : LruBuilderBase<K, V, TBuilder, TCacheReturn>
10+
where K : notnull
1011
{
1112
internal readonly LruInfo<K> info;
1213

BitFaster.Caching/Lru/Builder/LruInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace BitFaster.Caching.Lru.Builder
99
/// <typeparam name="K">The LRU key type</typeparam>
1010
// backcompat: make class internal
1111
public sealed class LruInfo<K>
12+
where K : notnull
1213
{
1314
private object? expiry = null;
1415

BitFaster.Caching/Lru/DiscretePolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace BitFaster.Caching.Lru
55
{
66
internal readonly struct DiscretePolicy<K, V> : IDiscreteItemPolicy<K, V>
7+
where K : notnull
78
{
89
private readonly IExpiryCalculator<K, V> expiry;
910
private readonly Time time;

BitFaster.Caching/Lru/IDiscreteItemPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/// <typeparam name="K"></typeparam>
77
/// <typeparam name="V"></typeparam>
88
public interface IDiscreteItemPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
9+
where K : notnull
910
{
1011
}
1112
}

BitFaster.Caching/Lru/IItemPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace BitFaster.Caching.Lru
99
/// <typeparam name="V">The type of the value.</typeparam>
1010
/// <typeparam name="I">The type of the LRU item.</typeparam>
1111
public interface IItemPolicy<in K, in V, I> where I : LruItem<K, V>
12+
where K : notnull
1213
{
1314
/// <summary>
1415
/// Creates an LRU item.

BitFaster.Caching/Lru/ITelemetryPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
77
/// <typeparam name="K">The type of the key.</typeparam>
88
/// <typeparam name="V">The type of the value.</typeparam>
99
public interface ITelemetryPolicy<K, V> : ICacheMetrics, ICacheEvents<K, V>
10+
where K : notnull
1011
{
1112
/// <summary>
1213
/// Increment the miss counter.

BitFaster.Caching/Lru/LongTickCountLruItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
77
/// <typeparam name="K">The type of the key.</typeparam>
88
/// <typeparam name="V">The type of the value.</typeparam>
99
public class LongTickCountLruItem<K, V> : LruItem<K, V>
10+
where K : notnull
1011
{
1112
/// <summary>
1213
/// Initializes a new instance of the LongTickCountLruItem class with the specified key and value.

BitFaster.Caching/Lru/LruItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
77
/// <typeparam name="K">The type of the key.</typeparam>
88
/// <typeparam name="V">The type of the value.</typeparam>
99
public class LruItem<K, V>
10+
where K : notnull
1011
{
1112
private volatile bool wasAccessed;
1213
private volatile bool wasRemoved;

BitFaster.Caching/Lru/LruPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
77
/// Discards the least recently used items first.
88
/// </summary>
99
public readonly struct LruPolicy<K, V> : IItemPolicy<K, V, LruItem<K, V>>
10+
where K : notnull
1011
{
1112
///<inheritdoc/>
1213
public TimeSpan TimeToLive => Defaults.Infinite;

BitFaster.Caching/Lru/NoTelemetryPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace BitFaster.Caching.Lru
1010
/// <typeparam name="K">The type of the key.</typeparam>
1111
/// <typeparam name="V">The type of the value.</typeparam>
1212
public struct NoTelemetryPolicy<K, V> : ITelemetryPolicy<K, V>
13+
where K : notnull
1314
{
1415
///<inheritdoc/>
1516
public double HitRatio => 0.0;

BitFaster.Caching/Lru/TLruLongTicksPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
88
/// recently used items first, and any item that has expired.
99
/// </summary>
1010
public readonly struct TLruLongTicksPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
11+
where K : notnull
1112
{
1213
private readonly Duration timeToLive;
1314

BitFaster.Caching/Lru/TelemetryPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace BitFaster.Caching.Lru
1111
/// <typeparam name="V">The type of the value</typeparam>
1212
[DebuggerDisplay("Hit = {Hits}, Miss = {Misses}, Upd = {Updated}, Evict = {Evicted}")]
1313
public struct TelemetryPolicy<K, V> : ITelemetryPolicy<K, V>
14+
where K : notnull
1415
{
1516
private Counter hitCount;
1617
private Counter missCount;

BitFaster.Caching/Lru/TickCountLruItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
88
/// <typeparam name="K">The type of the key.</typeparam>
99
/// <typeparam name="V">The type of the value.</typeparam>
1010
public class TickCountLruItem<K, V> : LruItem<K, V>
11+
where K : notnull
1112
{
1213
/// <summary>
1314
/// Initializes a new instance of the TickCountLruItem class with the specified key and value.

BitFaster.Caching/Lru/TimeStampedLruItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
88
/// <typeparam name="K">The type of the key.</typeparam>
99
/// <typeparam name="V">The type of the value.</typeparam>
1010
public class TimeStampedLruItem<K, V> : LruItem<K, V>
11+
where K : notnull
1112
{
1213
/// <summary>
1314
/// Initializes a new instance of the TimeStampedLruItem class with the specified key and value.

BitFaster.Caching/Lru/TlruDateTimePolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
88
/// recently used items first, and any item that has expired.
99
/// </summary>
1010
public readonly struct TLruDateTimePolicy<K, V> : IItemPolicy<K, V, TimeStampedLruItem<K, V>>
11+
where K : notnull
1112
{
1213
private readonly TimeSpan timeToLive;
1314

BitFaster.Caching/Lru/TlruTicksPolicy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace BitFaster.Caching.Lru
1313
/// value will wrap and time measurement will become invalid.
1414
/// </remarks>
1515
public readonly struct TLruTicksPolicy<K, V> : IItemPolicy<K, V, TickCountLruItem<K, V>>
16+
where K : notnull
1617
{
1718
private readonly int timeToLive;
1819

0 commit comments

Comments
 (0)