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
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void TestIntCapacity()
public void TestPartitionCapacity()
{
ICache<int, Disposable> lru = new ConcurrentLruBuilder<int, Disposable>()
.WithCapacity(new FavorFrequencyPartition(6))
.WithCapacity(new FavorWarmPartition(6))
.Build();

lru.Capacity.Should().Be(6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@

namespace BitFaster.Caching.UnitTests.Lru
{
public class FavorFrequencyPartitionTests
public class FavorWarmPartitionTests
{
[Fact]
public void WhenCapacityBelow3Throws()
{
Action constructor = () => { var x = new FavorFrequencyPartition(2); };
Action constructor = () => { var x = new FavorWarmPartition(2); };

constructor.Should().Throw<ArgumentOutOfRangeException>();
}

[Fact]
public void WhenRatioBelow0Throws()
{
Action constructor = () => { var x = new FavorFrequencyPartition(5, 0.0); };
Action constructor = () => { var x = new FavorWarmPartition(5, 0.0); };

constructor.Should().Throw<ArgumentOutOfRangeException>();
}

[Fact]
public void WhenRatioAbove1Throws()
{
Action constructor = () => { var x = new FavorFrequencyPartition(5, 1.0); };
Action constructor = () => { var x = new FavorWarmPartition(5, 1.0); };

constructor.Should().Throw<ArgumentOutOfRangeException>();
}
Expand All @@ -50,7 +50,7 @@ public void WhenRatioAbove1Throws()
[InlineData(100, 10, 80, 10)]
public void EqualPartitioningCreatesEqualQueues(int totalCapacity, int expectedHot, int expectedWarm, int expectedCold)
{
var p = new FavorFrequencyPartition(totalCapacity);
var p = new FavorWarmPartition(totalCapacity);

p.Hot.Should().Be(expectedHot);
p.Warm.Should().Be(expectedWarm);
Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching/Lru/Builder/LruBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected LruBuilderBase(LruInfo<K> info)
/// <returns>A ConcurrentLruBuilder</returns>
public TBuilder WithCapacity(int capacity)
{
this.info.Capacity = new FavorFrequencyPartition(capacity);
this.info.Capacity = new FavorWarmPartition(capacity);
return this as TBuilder;
}

Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching/Lru/Builder/LruInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BitFaster.Caching.Lru.Builder
{
public sealed class LruInfo<K>
{
public ICapacityPartition Capacity { get; set; } = new FavorFrequencyPartition(128);
public ICapacityPartition Capacity { get; set; } = new FavorWarmPartition(128);

public int ConcurrencyLevel { get; set; } = Defaults.ConcurrencyLevel;

Expand Down
4 changes: 2 additions & 2 deletions BitFaster.Caching/Lru/ConcurrentLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class ConcurrentLru<K, V> : TemplateConcurrentLru<K, V, LruItem<K,
/// </summary>
/// <param name="capacity">The maximum number of elements that the ConcurrentLru can contain.</param>
public ConcurrentLru(int capacity)
: base(Defaults.ConcurrencyLevel, new FavorFrequencyPartition(capacity), EqualityComparer<K>.Default, default, default)
: base(Defaults.ConcurrencyLevel, new FavorWarmPartition(capacity), EqualityComparer<K>.Default, default, default)
{
}

Expand All @@ -27,7 +27,7 @@ public ConcurrentLru(int capacity)
/// <param name="capacity">The maximum number of elements that the ConcurrentLru can contain.</param>
/// <param name="comparer">The IEqualityComparer<T> implementation to use when comparing keys.</param>
public ConcurrentLru(int concurrencyLevel, int capacity, IEqualityComparer<K> comparer)
: base(concurrencyLevel, new FavorFrequencyPartition(capacity), comparer, default, default)
: base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, default, default)
{
}

Expand Down
4 changes: 2 additions & 2 deletions BitFaster.Caching/Lru/ConcurrentTLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class ConcurrentTLru<K, V> : TemplateConcurrentLru<K, V, LongTickC
/// <param name="capacity">The maximum number of elements that the ConcurrentTLru can contain.</param>
/// <param name="timeToLive">The time to live for cached values.</param>
public ConcurrentTLru(int capacity, TimeSpan timeToLive)
: base(Defaults.ConcurrencyLevel, new FavorFrequencyPartition(capacity), EqualityComparer<K>.Default, new TLruLongTicksPolicy<K, V>(timeToLive), default)
: base(Defaults.ConcurrencyLevel, new FavorWarmPartition(capacity), EqualityComparer<K>.Default, new TLruLongTicksPolicy<K, V>(timeToLive), default)
{
}

Expand All @@ -29,7 +29,7 @@ public ConcurrentTLru(int capacity, TimeSpan timeToLive)
/// <param name="comparer">The IEqualityComparer<T> implementation to use when comparing keys.</param>
/// <param name="timeToLive">The time to live for cached values.</param>
public ConcurrentTLru(int concurrencyLevel, int capacity, IEqualityComparer<K> comparer, TimeSpan timeToLive)
: base(concurrencyLevel, new FavorFrequencyPartition(capacity), comparer, new TLruLongTicksPolicy<K, V>(timeToLive), default)
: base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, new TLruLongTicksPolicy<K, V>(timeToLive), default)
{
}

Expand Down
4 changes: 2 additions & 2 deletions BitFaster.Caching/Lru/FastConcurrentLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class FastConcurrentLru<K, V> : TemplateConcurrentLru<K, V, LruIte
/// </summary>
/// <param name="capacity">The maximum number of elements that the FastConcurrentLru can contain.</param>
public FastConcurrentLru(int capacity)
: base(Defaults.ConcurrencyLevel, new FavorFrequencyPartition(capacity), EqualityComparer<K>.Default, default, default)
: base(Defaults.ConcurrencyLevel, new FavorWarmPartition(capacity), EqualityComparer<K>.Default, default, default)
{
}

Expand All @@ -25,7 +25,7 @@ public FastConcurrentLru(int capacity)
/// <param name="capacity">The maximum number of elements that the FastConcurrentLru can contain.</param>
/// <param name="comparer">The IEqualityComparer<T> implementation to use when comparing keys.</param>
public FastConcurrentLru(int concurrencyLevel, int capacity, IEqualityComparer<K> comparer)
: base(concurrencyLevel, new FavorFrequencyPartition(capacity), comparer, default, default)
: base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, default, default)
{
}

Expand Down
4 changes: 2 additions & 2 deletions BitFaster.Caching/Lru/FastConcurrentTLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class FastConcurrentTLru<K, V> : TemplateConcurrentLru<K, V, LongT
/// <param name="capacity">The maximum number of elements that the FastConcurrentTLru can contain.</param>
/// <param name="timeToLive">The time to live for cached values.</param>
public FastConcurrentTLru(int capacity, TimeSpan timeToLive)
: base(Defaults.ConcurrencyLevel, new FavorFrequencyPartition(capacity), EqualityComparer<K>.Default, new TLruLongTicksPolicy<K, V>(timeToLive), default)
: base(Defaults.ConcurrencyLevel, new FavorWarmPartition(capacity), EqualityComparer<K>.Default, new TLruLongTicksPolicy<K, V>(timeToLive), default)
{
}

Expand All @@ -27,7 +27,7 @@ public FastConcurrentTLru(int capacity, TimeSpan timeToLive)
/// <param name="comparer">The IEqualityComparer<T> implementation to use when comparing keys.</param>
/// <param name="timeToLive">The time to live for cached values.</param>
public FastConcurrentTLru(int concurrencyLevel, int capacity, IEqualityComparer<K> comparer, TimeSpan timeToLive)
: base(concurrencyLevel, new FavorFrequencyPartition(capacity), comparer, new TLruLongTicksPolicy<K, V>(timeToLive), default)
: base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, new TLruLongTicksPolicy<K, V>(timeToLive), default)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace BitFaster.Caching.Lru
/// A capacity partitioning scheme that favors frequently accessed items by allocating 80%
/// capacity to the warm queue.
/// </summary>
public class FavorFrequencyPartition : ICapacityPartition
public class FavorWarmPartition : ICapacityPartition
{
private readonly int hotCapacity;
private readonly int warmCapacity;
Expand All @@ -20,12 +20,12 @@ public class FavorFrequencyPartition : ICapacityPartition
// This favors frequently accessed items.
public const double DefaultWarmRatio = 0.8;

public FavorFrequencyPartition(int totalCapacity)
public FavorWarmPartition(int totalCapacity)
: this(totalCapacity, DefaultWarmRatio)
{
}

public FavorFrequencyPartition(int totalCapacity, double warmRatio)
public FavorWarmPartition(int totalCapacity, double warmRatio)
{
var (hot, warm, cold) = ComputeQueueCapacity(totalCapacity, warmRatio);
this.hotCapacity = hot;
Expand Down