Skip to content

Commit ef35818

Browse files
authored
Consistent debug view (#307)
* debug view * rem ns * excl
1 parent b06f6f0 commit ef35818

13 files changed

+121
-9
lines changed

BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Threading.Tasks;
67

78
namespace BitFaster.Caching.Atomic
@@ -11,6 +12,7 @@ namespace BitFaster.Caching.Atomic
1112
/// </summary>
1213
/// <typeparam name="K">The type of keys in the cache.</typeparam>
1314
/// <typeparam name="V">The type of values in the cache.</typeparam>
15+
[DebuggerTypeProxy(typeof(AtomicFactoryAsyncCache<,>.AsyncCacheDebugView))]
1416
[DebuggerDisplay("Count = {Count}")]
1517
public sealed class AtomicFactoryAsyncCache<K, V> : IAsyncCache<K, V>
1618
{
@@ -133,5 +135,33 @@ protected override ItemUpdatedEventArgs<K, V> TranslateOnUpdated(ItemUpdatedEven
133135
return new ItemUpdatedEventArgs<K, V>(inner.Key, inner.OldValue.ValueIfCreated, inner.NewValue.ValueIfCreated);
134136
}
135137
}
138+
139+
[ExcludeFromCodeCoverage]
140+
internal class AsyncCacheDebugView
141+
{
142+
private readonly IAsyncCache<K, V> cache;
143+
144+
public AsyncCacheDebugView(IAsyncCache<K, V> cache)
145+
{
146+
this.cache = cache;
147+
}
148+
149+
public KeyValuePair<K, V>[] Items
150+
{
151+
get
152+
{
153+
var items = new KeyValuePair<K, V>[cache.Count];
154+
155+
int index = 0;
156+
foreach (var kvp in cache)
157+
{
158+
items[index++] = kvp;
159+
}
160+
return items;
161+
}
162+
}
163+
164+
public ICacheMetrics Metrics => cache.Metrics.Value;
165+
}
136166
}
137167
}

BitFaster.Caching/Atomic/AtomicFactoryCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace BitFaster.Caching.Atomic
1010
/// </summary>
1111
/// <typeparam name="K">The type of keys in the cache.</typeparam>
1212
/// <typeparam name="V">The type of values in the cache.</typeparam>
13+
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
1314
[DebuggerDisplay("Count = {Count}")]
1415
public sealed class AtomicFactoryCache<K, V> : ICache<K, V>
1516
{

BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace BitFaster.Caching.Atomic
1212
/// </summary>
1313
/// <typeparam name="K">The type of keys in the cache.</typeparam>
1414
/// <typeparam name="V">The type of values in the cache.</typeparam>
15+
[DebuggerTypeProxy(typeof(ScopedAsyncCacheDebugView<,>))]
1516
[DebuggerDisplay("Count = {Count}")]
1617
public sealed class AtomicFactoryScopedAsyncCache<K, V> : IScopedAsyncCache<K, V> where V : IDisposable
1718
{

BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace BitFaster.Caching.Atomic
1111
/// </summary>
1212
/// <typeparam name="K">The type of keys in the cache.</typeparam>
1313
/// <typeparam name="V">The type of values in the cache.</typeparam>
14+
[DebuggerTypeProxy(typeof(ScopedCacheDebugView<,>))]
1415
[DebuggerDisplay("Count = {Count}")]
1516
public sealed class AtomicFactoryScopedCache<K, V> : IScopedCache<K, V> where V : IDisposable
1617
{

BitFaster.Caching/Lru/LruDebugView.cs renamed to BitFaster.Caching/CacheDebugView.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
using System;
2-
using System.Collections;
1+

32
using System.Collections.Generic;
43
using System.Diagnostics.CodeAnalysis;
54

6-
namespace BitFaster.Caching.Lru
5+
namespace BitFaster.Caching
76
{
87
[ExcludeFromCodeCoverage]
9-
internal class LruDebugView<K, V>
8+
internal class CacheDebugView<K, V>
109
{
1110
private readonly ICache<K, V> cache;
1211

13-
public LruDebugView(ICache<K, V> cache)
12+
public CacheDebugView(ICache<K, V> cache)
1413
{
1514
if (cache is null)
1615
{

BitFaster.Caching/Lru/ConcurrentLru.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace BitFaster.Caching.Lru
55
{
66
///<inheritdoc/>
7-
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
7+
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
88
[DebuggerDisplay("Count = {Count}/{Capacity}")]
99
public sealed class ConcurrentLru<K, V> : ConcurrentLruCore<K, V, LruItem<K, V>, LruPolicy<K, V>, TelemetryPolicy<K, V>>
1010
{

BitFaster.Caching/Lru/ConcurrentTLru.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace BitFaster.Caching.Lru
66
{
77
///<inheritdoc/>
8-
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
8+
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
99
[DebuggerDisplay("Count = {Count}/{Capacity}")]
1010
public sealed class ConcurrentTLru<K, V> : ConcurrentLruCore<K, V, LongTickCountLruItem<K, V>, TLruLongTicksPolicy<K, V>, TelemetryPolicy<K, V>>
1111
{

BitFaster.Caching/Lru/FastConcurrentLru.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace BitFaster.Caching.Lru
55
{
66
///<inheritdoc/>
7-
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
7+
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
88
[DebuggerDisplay("Count = {Count}/{Capacity}")]
99
public sealed class FastConcurrentLru<K, V> : ConcurrentLruCore<K, V, LruItem<K, V>, LruPolicy<K, V>, NoTelemetryPolicy<K, V>>
1010
{

BitFaster.Caching/Lru/FastConcurrentTLru.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace BitFaster.Caching.Lru
66
{
77
///<inheritdoc/>
8-
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
8+
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
99
[DebuggerDisplay("Count = {Count}/{Capacity}")]
1010
public sealed class FastConcurrentTLru<K, V> : ConcurrentLruCore<K, V, LongTickCountLruItem<K, V>, TLruLongTicksPolicy<K, V>, NoTelemetryPolicy<K, V>>
1111
{

BitFaster.Caching/ScopedAsyncCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace BitFaster.Caching
1414
/// </summary>
1515
/// <typeparam name="K">The type of keys in the cache.</typeparam>
1616
/// <typeparam name="V">The type of values in the cache.</typeparam>
17+
[DebuggerTypeProxy(typeof(ScopedAsyncCacheDebugView<,>))]
1718
[DebuggerDisplay("Count = {Count}")]
1819
public sealed class ScopedAsyncCache<K, V> : IScopedAsyncCache<K, V> where V : IDisposable
1920
{

0 commit comments

Comments
 (0)