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
30 changes: 30 additions & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace BitFaster.Caching.Atomic
Expand All @@ -11,6 +12,7 @@ namespace BitFaster.Caching.Atomic
/// </summary>
/// <typeparam name="K">The type of keys in the cache.</typeparam>
/// <typeparam name="V">The type of values in the cache.</typeparam>
[DebuggerTypeProxy(typeof(AtomicFactoryAsyncCache<,>.AsyncCacheDebugView))]
[DebuggerDisplay("Count = {Count}")]
public sealed class AtomicFactoryAsyncCache<K, V> : IAsyncCache<K, V>
{
Expand Down Expand Up @@ -133,5 +135,33 @@ protected override ItemUpdatedEventArgs<K, V> TranslateOnUpdated(ItemUpdatedEven
return new ItemUpdatedEventArgs<K, V>(inner.Key, inner.OldValue.ValueIfCreated, inner.NewValue.ValueIfCreated);
}
}

[ExcludeFromCodeCoverage]
internal class AsyncCacheDebugView
{
private readonly IAsyncCache<K, V> cache;

public AsyncCacheDebugView(IAsyncCache<K, V> cache)
{
this.cache = cache;
}

public KeyValuePair<K, V>[] Items
{
get
{
var items = new KeyValuePair<K, V>[cache.Count];

int index = 0;
foreach (var kvp in cache)
{
items[index++] = kvp;
}
return items;
}
}

public ICacheMetrics Metrics => cache.Metrics.Value;
}
}
}
1 change: 1 addition & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace BitFaster.Caching.Atomic
/// </summary>
/// <typeparam name="K">The type of keys in the cache.</typeparam>
/// <typeparam name="V">The type of values in the cache.</typeparam>
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
public sealed class AtomicFactoryCache<K, V> : ICache<K, V>
{
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace BitFaster.Caching.Atomic
/// </summary>
/// <typeparam name="K">The type of keys in the cache.</typeparam>
/// <typeparam name="V">The type of values in the cache.</typeparam>
[DebuggerTypeProxy(typeof(ScopedAsyncCacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
public sealed class AtomicFactoryScopedAsyncCache<K, V> : IScopedAsyncCache<K, V> where V : IDisposable
{
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace BitFaster.Caching.Atomic
/// </summary>
/// <typeparam name="K">The type of keys in the cache.</typeparam>
/// <typeparam name="V">The type of values in the cache.</typeparam>
[DebuggerTypeProxy(typeof(ScopedCacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
public sealed class AtomicFactoryScopedCache<K, V> : IScopedCache<K, V> where V : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System.Collections;

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace BitFaster.Caching.Lru
namespace BitFaster.Caching
{
[ExcludeFromCodeCoverage]
internal class LruDebugView<K, V>
internal class CacheDebugView<K, V>
{
private readonly ICache<K, V> cache;

public LruDebugView(ICache<K, V> cache)
public CacheDebugView(ICache<K, V> cache)
{
if (cache is null)
{
Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching/Lru/ConcurrentLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace BitFaster.Caching.Lru
{
///<inheritdoc/>
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}/{Capacity}")]
public sealed class ConcurrentLru<K, V> : ConcurrentLruCore<K, V, LruItem<K, V>, LruPolicy<K, V>, TelemetryPolicy<K, V>>
{
Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching/Lru/ConcurrentTLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BitFaster.Caching.Lru
{
///<inheritdoc/>
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}/{Capacity}")]
public sealed class ConcurrentTLru<K, V> : ConcurrentLruCore<K, V, LongTickCountLruItem<K, V>, TLruLongTicksPolicy<K, V>, TelemetryPolicy<K, V>>
{
Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching/Lru/FastConcurrentLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace BitFaster.Caching.Lru
{
///<inheritdoc/>
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}/{Capacity}")]
public sealed class FastConcurrentLru<K, V> : ConcurrentLruCore<K, V, LruItem<K, V>, LruPolicy<K, V>, NoTelemetryPolicy<K, V>>
{
Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching/Lru/FastConcurrentTLru.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace BitFaster.Caching.Lru
{
///<inheritdoc/>
[DebuggerTypeProxy(typeof(LruDebugView<,>))]
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}/{Capacity}")]
public sealed class FastConcurrentTLru<K, V> : ConcurrentLruCore<K, V, LongTickCountLruItem<K, V>, TLruLongTicksPolicy<K, V>, NoTelemetryPolicy<K, V>>
{
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/ScopedAsyncCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace BitFaster.Caching
/// </summary>
/// <typeparam name="K">The type of keys in the cache.</typeparam>
/// <typeparam name="V">The type of values in the cache.</typeparam>
[DebuggerTypeProxy(typeof(ScopedAsyncCacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
public sealed class ScopedAsyncCache<K, V> : IScopedAsyncCache<K, V> where V : IDisposable
{
Expand Down
39 changes: 39 additions & 0 deletions BitFaster.Caching/ScopedAsyncCacheDebugView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace BitFaster.Caching
{
[ExcludeFromCodeCoverage]
internal class ScopedAsyncCacheDebugView<K, V> where V : IDisposable
{
private readonly IScopedAsyncCache<K, V> cache;

public ScopedAsyncCacheDebugView(IScopedAsyncCache<K, V> cache)
{
if (cache is null)
{
Ex.ThrowArgNull(ExceptionArgument.cache);
}

this.cache = cache;
}

public KeyValuePair<K, Scoped<V>>[] Items
{
get
{
var items = new KeyValuePair<K, Scoped<V>>[cache.Count];

var index = 0;
foreach (var kvp in cache)
{
items[index++] = kvp;
}
return items;
}
}

public ICacheMetrics Metrics => cache.Metrics.Value;
}
}
1 change: 1 addition & 0 deletions BitFaster.Caching/ScopedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace BitFaster.Caching
/// </summary>
/// <typeparam name="K">The type of keys in the cache.</typeparam>
/// <typeparam name="V">The type of values in the cache.</typeparam>
[DebuggerTypeProxy(typeof(ScopedCacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
public sealed class ScopedCache<K, V> : IScopedCache<K, V> where V : IDisposable
{
Expand Down
39 changes: 39 additions & 0 deletions BitFaster.Caching/ScopedCacheDebugView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace BitFaster.Caching
{
[ExcludeFromCodeCoverage]
internal class ScopedCacheDebugView<K, V> where V : IDisposable
{
private readonly IScopedCache<K, V> cache;

public ScopedCacheDebugView(IScopedCache<K, V> cache)
{
if (cache is null)
{
Ex.ThrowArgNull(ExceptionArgument.cache);
}

this.cache = cache;
}

public KeyValuePair<K, Scoped<V>>[] Items
{
get
{
var items = new KeyValuePair<K, Scoped<V>>[cache.Count];

var index = 0;
foreach (var kvp in cache)
{
items[index++] = kvp;
}
return items;
}
}

public ICacheMetrics Metrics => cache.Metrics.Value;
}
}