Skip to content

Commit

Permalink
Add missing key not null constraints (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfaster authored May 24, 2024
1 parent 5483cbf commit 8934324
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions BitFaster.Caching/CacheDebugView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace BitFaster.Caching
{
[ExcludeFromCodeCoverage]
internal class CacheDebugView<K, V>
where K : notnull
{
private readonly ICache<K, V> cache;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lfu/Builder/LfuBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace BitFaster.Caching.Lfu.Builder
/// <typeparam name="TBuilder">The type of the builder.</typeparam>
/// <typeparam name="TCacheReturn">The return type of the builder.</typeparam>
public abstract class LfuBuilderBase<K, V, TBuilder, TCacheReturn> where TBuilder : LfuBuilderBase<K, V, TBuilder, TCacheReturn>
where K : notnull
{
internal readonly LfuInfo<K> info;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lfu/Builder/LfuInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace BitFaster.Caching.Lfu.Builder
{
internal sealed class LfuInfo<K>
where K : notnull
{
private object? expiry = null;

Expand Down
2 changes: 2 additions & 0 deletions BitFaster.Caching/Lfu/LfuNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace BitFaster.Caching.Lfu
{
internal class LfuNode<K, V>
where K : notnull
{
internal LfuNodeList<K, V> list;
internal LfuNode<K, V> next;
Expand Down Expand Up @@ -66,6 +67,7 @@ internal enum Position
}

internal sealed class AccessOrderNode<K, V> : LfuNode<K, V>
where K : notnull
{
public AccessOrderNode(K k, V v) : base(k, v)
{
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/AfterAccessPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
/// Implement an expire after access policy.
/// </summary>
internal readonly struct AfterAccessPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
where K : notnull
{
private readonly Duration timeToLive;
private readonly Time time;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/Builder/LruBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru.Builder
/// Recursive generic base class enables builder inheritance.
/// </summary>
public abstract class LruBuilderBase<K, V, TBuilder, TCacheReturn> where TBuilder : LruBuilderBase<K, V, TBuilder, TCacheReturn>
where K : notnull
{
internal readonly LruInfo<K> info;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/Builder/LruInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace BitFaster.Caching.Lru.Builder
/// <typeparam name="K">The LRU key type</typeparam>
// backcompat: make class internal
public sealed class LruInfo<K>
where K : notnull
{
private object? expiry = null;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/DiscretePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace BitFaster.Caching.Lru
{
internal readonly struct DiscretePolicy<K, V> : IDiscreteItemPolicy<K, V>
where K : notnull
{
private readonly IExpiryCalculator<K, V> expiry;
private readonly Time time;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/IDiscreteItemPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/// <typeparam name="K"></typeparam>
/// <typeparam name="V"></typeparam>
public interface IDiscreteItemPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
where K : notnull
{
}
}
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/IItemPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="V">The type of the value.</typeparam>
/// <typeparam name="I">The type of the LRU item.</typeparam>
public interface IItemPolicy<in K, in V, I> where I : LruItem<K, V>
where K : notnull
{
/// <summary>
/// Creates an LRU item.
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/ITelemetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="K">The type of the key.</typeparam>
/// <typeparam name="V">The type of the value.</typeparam>
public interface ITelemetryPolicy<K, V> : ICacheMetrics, ICacheEvents<K, V>
where K : notnull
{
/// <summary>
/// Increment the miss counter.
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/LongTickCountLruItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="K">The type of the key.</typeparam>
/// <typeparam name="V">The type of the value.</typeparam>
public class LongTickCountLruItem<K, V> : LruItem<K, V>
where K : notnull
{
/// <summary>
/// Initializes a new instance of the LongTickCountLruItem class with the specified key and value.
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/LruItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="K">The type of the key.</typeparam>
/// <typeparam name="V">The type of the value.</typeparam>
public class LruItem<K, V>
where K : notnull
{
private volatile bool wasAccessed;
private volatile bool wasRemoved;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/LruPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lru
/// Discards the least recently used items first.
/// </summary>
public readonly struct LruPolicy<K, V> : IItemPolicy<K, V, LruItem<K, V>>
where K : notnull
{
///<inheritdoc/>
public TimeSpan TimeToLive => Defaults.Infinite;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/NoTelemetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="K">The type of the key.</typeparam>
/// <typeparam name="V">The type of the value.</typeparam>
public struct NoTelemetryPolicy<K, V> : ITelemetryPolicy<K, V>
where K : notnull
{
///<inheritdoc/>
public double HitRatio => 0.0;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/TLruLongTicksPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
/// recently used items first, and any item that has expired.
/// </summary>
public readonly struct TLruLongTicksPolicy<K, V> : IItemPolicy<K, V, LongTickCountLruItem<K, V>>
where K : notnull
{
private readonly Duration timeToLive;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/TelemetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="V">The type of the value</typeparam>
[DebuggerDisplay("Hit = {Hits}, Miss = {Misses}, Upd = {Updated}, Evict = {Evicted}")]
public struct TelemetryPolicy<K, V> : ITelemetryPolicy<K, V>
where K : notnull
{
private Counter hitCount;
private Counter missCount;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/TickCountLruItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="K">The type of the key.</typeparam>
/// <typeparam name="V">The type of the value.</typeparam>
public class TickCountLruItem<K, V> : LruItem<K, V>
where K : notnull
{
/// <summary>
/// Initializes a new instance of the TickCountLruItem class with the specified key and value.
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/TimeStampedLruItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
/// <typeparam name="K">The type of the key.</typeparam>
/// <typeparam name="V">The type of the value.</typeparam>
public class TimeStampedLruItem<K, V> : LruItem<K, V>
where K : notnull
{
/// <summary>
/// Initializes a new instance of the TimeStampedLruItem class with the specified key and value.
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/TlruDateTimePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace BitFaster.Caching.Lru
/// recently used items first, and any item that has expired.
/// </summary>
public readonly struct TLruDateTimePolicy<K, V> : IItemPolicy<K, V, TimeStampedLruItem<K, V>>
where K : notnull
{
private readonly TimeSpan timeToLive;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lru/TlruTicksPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace BitFaster.Caching.Lru
/// value will wrap and time measurement will become invalid.
/// </remarks>
public readonly struct TLruTicksPolicy<K, V> : IItemPolicy<K, V, TickCountLruItem<K, V>>
where K : notnull
{
private readonly int timeToLive;

Expand Down

0 comments on commit 8934324

Please sign in to comment.