Skip to content

Commit 9c5d849

Browse files
author
Alex Peck
committed
remove metrics/events from core
1 parent e361650 commit 9c5d849

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Diagnostics;
54
using System.Linq;
65
using System.Threading.Tasks;
7-
using BitFaster.Caching.Buffers;
86
using BitFaster.Caching.Lfu;
97
using BitFaster.Caching.Scheduler;
108
using BitFaster.Caching.UnitTests.Lru;
@@ -572,7 +570,11 @@ public void WhenItemsAddedGenericEnumerateContainsKvps()
572570
cache.GetOrAdd(1, k => k + 1);
573571
cache.GetOrAdd(2, k => k + 1);
574572

575-
cache.Should().BeEquivalentTo(new[] { new KeyValuePair<int, int>(1, 2), new KeyValuePair<int, int>(2, 3) });
573+
var enumerator = cache.GetEnumerator();
574+
enumerator.MoveNext().Should().BeTrue();
575+
enumerator.Current.Should().Be(new KeyValuePair<int, int>(1, 2));
576+
enumerator.MoveNext().Should().BeTrue();
577+
enumerator.Current.Should().Be(new KeyValuePair<int, int>(2, 3));
576578
}
577579

578580
[Fact]

BitFaster.Caching/Lfu/ConcurrentLfu.cs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ private void DrainBuffers()
8585
public int Count => core.Count;
8686

8787
///<inheritdoc/>
88-
public Optional<ICacheMetrics> Metrics => core.Metrics;
88+
public Optional<ICacheMetrics> Metrics => new(this.core.metrics);
8989

9090
///<inheritdoc/>
91-
public Optional<ICacheEvents<K, V>> Events => core.Events;
91+
public Optional<ICacheEvents<K, V>> Events => Optional<ICacheEvents<K, V>>.None();
9292

9393
///<inheritdoc/>
94-
public CachePolicy Policy => core.Policy;
94+
public CachePolicy Policy => new(new Optional<IBoundedPolicy>(this), Optional<ITimePolicy>.None());
9595

9696
///<inheritdoc/>
9797
public ICollection<K> Keys => core.Keys;
@@ -127,12 +127,6 @@ public void Clear()
127127
core.Clear();
128128
}
129129

130-
///<inheritdoc/>
131-
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
132-
{
133-
return core.GetEnumerator();
134-
}
135-
136130
///<inheritdoc/>
137131
public V GetOrAdd(K key, Func<K, V> valueFactory)
138132
{
@@ -202,10 +196,17 @@ public bool TryUpdate(K key, V value)
202196
return core.TryUpdate(key, value);
203197
}
204198

199+
///<inheritdoc/>
200+
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
201+
{
202+
return core.GetEnumerator();
203+
}
204+
205205
///<inheritdoc/>
206206
IEnumerator IEnumerable.GetEnumerator()
207207
{
208-
return ((ConcurrentLfuCore<K, V, AccessOrderNode<K, V>, AccessOrderPolicy<K, V>>)core).GetEnumerator();
208+
return core.GetEnumerator();
209+
//return ((ConcurrentLfuCore<K, V, AccessOrderNode<K, V>, AccessOrderPolicy<K, V>>)core).GetEnumerator();
209210
}
210211

211212
#if DEBUG
@@ -276,7 +277,7 @@ public KeyValuePair<K, V>[] Items
276277
/// Based on the Caffeine library by ben.manes@gmail.com (Ben Manes).
277278
/// https://github.com/ben-manes/caffeine
278279

279-
internal struct ConcurrentLfuCore<K, V, N, P> : ICache<K, V>, IAsyncCache<K, V>, IBoundedPolicy
280+
internal struct ConcurrentLfuCore<K, V, N, P> : IBoundedPolicy
280281
where N : LfuNode<K, V>
281282
where P : struct, INodePolicy<K, V, N>
282283
{
@@ -289,7 +290,7 @@ internal struct ConcurrentLfuCore<K, V, N, P> : ICache<K, V>, IAsyncCache<K, V>,
289290
internal readonly StripedMpscBuffer<N> readBuffer;
290291
internal readonly MpscBoundedBuffer<N> writeBuffer;
291292

292-
private readonly CacheMetrics metrics = new();
293+
internal readonly CacheMetrics metrics = new();
293294

294295
private readonly CmSketch<K> cmSketch;
295296

@@ -342,12 +343,6 @@ public ConcurrentLfuCore(int concurrencyLevel, int capacity, IScheduler schedule
342343

343344
public int Capacity => this.capacity.Capacity;
344345

345-
public Optional<ICacheMetrics> Metrics => new(this.metrics);
346-
347-
public Optional<ICacheEvents<K, V>> Events => Optional<ICacheEvents<K, V>>.None();
348-
349-
public CachePolicy Policy => new(new Optional<IBoundedPolicy>(this), Optional<ITimePolicy>.None());
350-
351346
public ICollection<K> Keys => this.dictionary.Keys;
352347

353348
public IScheduler Scheduler => scheduler;
@@ -662,11 +657,6 @@ private void ScheduleAfterWrite()
662657
}
663658
}
664659

665-
IEnumerator IEnumerable.GetEnumerator()
666-
{
667-
return ((ConcurrentLfuCore<K, V, N, P>)this).GetEnumerator();
668-
}
669-
670660
private void TryScheduleDrain()
671661
{
672662
if (this.drainStatus.VolatileRead() >= DrainStatus.ProcessingToIdle)

0 commit comments

Comments
 (0)