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
1 change: 1 addition & 0 deletions BitFaster.Caching/Atomic/AsyncAtomicFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace BitFaster.Caching.Atomic
/// <typeparam name="V">The type of the value.</typeparam>
[DebuggerDisplay("IsValueCreated={IsValueCreated}, Value={ValueIfCreated}")]
public sealed class AsyncAtomicFactory<K, V> : IEquatable<AsyncAtomicFactory<K, V>>
where K : notnull
{
private Initializer initializer;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Atomic/AtomicFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace BitFaster.Caching.Atomic
/// <typeparam name="V">The type of the value.</typeparam>
[DebuggerDisplay("IsValueCreated={IsValueCreated}, Value={ValueIfCreated}")]
public sealed class AtomicFactory<K, V> : IEquatable<AtomicFactory<K, V>>
where K : notnull
{
private Initializer initializer;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace BitFaster.Caching.Atomic
[DebuggerTypeProxy(typeof(AtomicFactoryAsyncCache<,>.AsyncCacheDebugView))]
[DebuggerDisplay("Count = {Count}")]
public sealed class AtomicFactoryAsyncCache<K, V> : IAsyncCache<K, V>
where K : notnull
{
private readonly ICache<K, AsyncAtomicFactory<K, V>> cache;
private readonly Optional<ICacheEvents<K, V>> events;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace BitFaster.Caching.Atomic
[DebuggerTypeProxy(typeof(CacheDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
public sealed class AtomicFactoryCache<K, V> : ICache<K, V>
where K : notnull
{
private readonly ICache<K, AtomicFactory<K, V>> cache;
private readonly Optional<ICacheEvents<K, V>> events;
Expand Down
4 changes: 3 additions & 1 deletion BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace BitFaster.Caching.Atomic
/// <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
public sealed class AtomicFactoryScopedAsyncCache<K, V> : IScopedAsyncCache<K, V>
where K : notnull
where V : IDisposable
{
private readonly ICache<K, ScopedAsyncAtomicFactory<K, V>> cache;
private readonly Optional<ICacheEvents<K, Scoped<V>>> events;
Expand Down
4 changes: 3 additions & 1 deletion BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace BitFaster.Caching.Atomic
/// <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
public sealed class AtomicFactoryScopedCache<K, V> : IScopedCache<K, V>
where K : notnull
where V : IDisposable
{
private readonly ICache<K, ScopedAtomicFactory<K, V>> cache;
private readonly Optional<ICacheEvents<K, Scoped<V>>> events;
Expand Down
10 changes: 10 additions & 0 deletions BitFaster.Caching/Atomic/ConcurrentDictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class ConcurrentDictionaryExtensions
/// <param name="valueFactory">The function used to generate a value for the key.</param>
/// <returns>The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.</returns>
public static V GetOrAdd<K, V>(this ConcurrentDictionary<K, AtomicFactory<K, V>> dictionary, K key, Func<K, V> valueFactory)
where K : notnull
{
var atomicFactory = dictionary.GetOrAdd(key, _ => new AtomicFactory<K, V>());
return atomicFactory.GetValue(key, valueFactory);
Expand All @@ -32,6 +33,7 @@ public static V GetOrAdd<K, V>(this ConcurrentDictionary<K, AtomicFactory<K, V>>
/// <param name="factoryArgument">An argument value to pass into valueFactory.</param>
/// <returns>The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.</returns>
public static V GetOrAdd<K, V, TArg>(this ConcurrentDictionary<K, AtomicFactory<K, V>> dictionary, K key, Func<K, TArg, V> valueFactory, TArg factoryArgument)
where K : notnull
{
var atomicFactory = dictionary.GetOrAdd(key, _ => new AtomicFactory<K, V>());
return atomicFactory.GetValue(key, valueFactory, factoryArgument);
Expand All @@ -45,6 +47,7 @@ public static V GetOrAdd<K, V, TArg>(this ConcurrentDictionary<K, AtomicFactory<
/// <param name="valueFactory">The function used to generate a value for the key.</param>
/// <returns>The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.</returns>
public static ValueTask<V> GetOrAddAsync<K, V>(this ConcurrentDictionary<K, AsyncAtomicFactory<K, V>> dictionary, K key, Func<K, Task<V>> valueFactory)
where K : notnull
{
var asyncAtomicFactory = dictionary.GetOrAdd(key, _ => new AsyncAtomicFactory<K, V>());
return asyncAtomicFactory.GetValueAsync(key, valueFactory);
Expand All @@ -59,6 +62,7 @@ public static ValueTask<V> GetOrAddAsync<K, V>(this ConcurrentDictionary<K, Asyn
/// <param name="factoryArgument">An argument value to pass into valueFactory.</param>
/// <returns>The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value if the key was not in the dictionary.</returns>
public static ValueTask<V> GetOrAddAsync<K, V, TArg>(this ConcurrentDictionary<K, AsyncAtomicFactory<K, V>> dictionary, K key, Func<K, TArg, Task<V>> valueFactory, TArg factoryArgument)
where K : notnull
{
var asyncAtomicFactory = dictionary.GetOrAdd(key, _ => new AsyncAtomicFactory<K, V>());
return asyncAtomicFactory.GetValueAsync(key, valueFactory, factoryArgument);
Expand All @@ -72,6 +76,7 @@ public static ValueTask<V> GetOrAddAsync<K, V, TArg>(this ConcurrentDictionary<K
/// <param name="value">When this method returns, contains the object from the ConcurrentDictionary that has the specified key, or the default value of the type if the operation failed.</param>
/// <returns>true if the key was found in the ConcurrentDictionary; otherwise, false.</returns>
public static bool TryGetValue<K, V>(this ConcurrentDictionary<K, AtomicFactory<K, V>> dictionary, K key, out V value)
where K : notnull
{
AtomicFactory<K, V> output;
var ret = dictionary.TryGetValue(key, out output);
Expand All @@ -93,6 +98,7 @@ public static bool TryGetValue<K, V>(this ConcurrentDictionary<K, AtomicFactory<
/// <param name="key">The key of the value to get.</param>
/// <param name="value">When this method returns, contains the object from the ConcurrentDictionary that has the specified key, or the default value of the type if the operation failed.</param>
public static bool TryGetValue<K, V>(this ConcurrentDictionary<K, AsyncAtomicFactory<K, V>> dictionary, K key, out V value)
where K : notnull
{
AsyncAtomicFactory<K, V> output;
var ret = dictionary.TryGetValue(key, out output);
Expand All @@ -114,6 +120,7 @@ public static bool TryGetValue<K, V>(this ConcurrentDictionary<K, AsyncAtomicFac
/// <param name="item">The KeyValuePair representing the key and value to remove.</param>
/// <returns>true if the object was removed successfully; otherwise, false.</returns>
public static bool TryRemove<K, V>(this ConcurrentDictionary<K, AtomicFactory<K, V>> dictionary, KeyValuePair<K, V> item)
where K : notnull
{
var kvp = new KeyValuePair<K, AtomicFactory<K, V>>(item.Key, new AtomicFactory<K, V>(item.Value));
#if NET6_0_OR_GREATER
Expand All @@ -131,6 +138,7 @@ public static bool TryRemove<K, V>(this ConcurrentDictionary<K, AtomicFactory<K,
/// <param name="item">The KeyValuePair representing the key and value to remove.</param>
/// <returns>true if the object was removed successfully; otherwise, false.</returns>
public static bool TryRemove<K, V>(this ConcurrentDictionary<K, AsyncAtomicFactory<K, V>> dictionary, KeyValuePair<K, V> item)
where K : notnull
{
var kvp = new KeyValuePair<K, AsyncAtomicFactory<K, V>>(item.Key, new AsyncAtomicFactory<K, V>(item.Value));
#if NET6_0_OR_GREATER
Expand All @@ -149,6 +157,7 @@ public static bool TryRemove<K, V>(this ConcurrentDictionary<K, AsyncAtomicFacto
/// <param name="value">When this method returns, contains the object removed from the ConcurrentDictionary, or the default value of the TValue type if key does not exist.</param>
/// <returns>true if the object was removed successfully; otherwise, false.</returns>
public static bool TryRemove<K, V>(this ConcurrentDictionary<K, AtomicFactory<K, V>> dictionary, K key, out V value)
where K : notnull
{
if (dictionary.TryRemove(key, out var atomic))
{
Expand All @@ -168,6 +177,7 @@ public static bool TryRemove<K, V>(this ConcurrentDictionary<K, AtomicFactory<K,
/// <param name="value">When this method returns, contains the object removed from the ConcurrentDictionary, or the default value of the TValue type if key does not exist.</param>
/// <returns>true if the object was removed successfully; otherwise, false.</returns>
public static bool TryRemove<K, V>(this ConcurrentDictionary<K, AsyncAtomicFactory<K, V>> dictionary, K key, out V value)
where K : notnull
{
if (dictionary.TryRemove(key, out var atomic))
{
Expand Down
4 changes: 3 additions & 1 deletion BitFaster.Caching/Atomic/ScopedAsyncAtomicFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace BitFaster.Caching.Atomic
/// <typeparam name="K">The type of the key.</typeparam>
/// <typeparam name="V">The type of the value.</typeparam>
[DebuggerDisplay("IsScopeCreated={initializer == null}, Value={ScopeIfCreated}")]
public sealed class ScopedAsyncAtomicFactory<K, V> : IScoped<V>, IDisposable where V : IDisposable
public sealed class ScopedAsyncAtomicFactory<K, V> : IScoped<V>, IDisposable
where K : notnull
where V : IDisposable
{
private Scoped<V> scope;
private Initializer initializer;
Expand Down
4 changes: 3 additions & 1 deletion BitFaster.Caching/Atomic/ScopedAtomicFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace BitFaster.Caching.Atomic
///</list>
/// </remarks>
[DebuggerDisplay("IsScopeCreated={initializer == null}, Value={ScopeIfCreated}")]
public sealed class ScopedAtomicFactory<K, V> : IScoped<V>, IDisposable where V : IDisposable
public sealed class ScopedAtomicFactory<K, V> : IScoped<V>, IDisposable
where K : notnull
where V : IDisposable
{
private Scoped<V> scope;
private Initializer initializer;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/BitFaster.Caching.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<IsTrimmable>true</IsTrimmable>
<Nullable>disable</Nullable>
<!--Package Validation-->
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>2.4.0</PackageValidationBaselineVersion>
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lfu/Builder/AsyncConcurrentLfuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace BitFaster.Caching.Lfu.Builder
/// <typeparam name="K">The type of the cache key.</typeparam>
/// <typeparam name="V">The type of the cache value.</typeparam>
public sealed class AsyncConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, AsyncConcurrentLfuBuilder<K, V>, IAsyncCache<K, V>>
where K : notnull
{
internal AsyncConcurrentLfuBuilder(LfuInfo<K> info)
: base(info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace BitFaster.Caching.Lfu.Builder
/// <typeparam name="K">The type of the cache key.</typeparam>
/// <typeparam name="V">The type of the cache value.</typeparam>
public sealed class AtomicAsyncConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, AtomicAsyncConcurrentLfuBuilder<K, V>, IAsyncCache<K, V>>
where K : notnull
{
private readonly ConcurrentLfuBuilder<K, AsyncAtomicFactory<K, V>> inner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace BitFaster.Caching.Lfu.Builder
/// <typeparam name="K">The type of the cache key.</typeparam>
/// <typeparam name="V">The type of the cache value.</typeparam>
public sealed class AtomicConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, AtomicConcurrentLfuBuilder<K, V>, ICache<K, V>>
where K : notnull
{
private readonly ConcurrentLfuBuilder<K, AtomicFactory<K, V>> inner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace BitFaster.Caching.Lfu.Builder
/// </summary>
/// <typeparam name="K">The type of the cache key.</typeparam>
/// <typeparam name="V">The type of the cache value.</typeparam>
public sealed class AtomicScopedAsyncConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, AtomicScopedAsyncConcurrentLfuBuilder<K, V>, IScopedAsyncCache<K, V>> where V : IDisposable
public sealed class AtomicScopedAsyncConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, AtomicScopedAsyncConcurrentLfuBuilder<K, V>, IScopedAsyncCache<K, V>>
where K : notnull
where V : IDisposable
{
private readonly AsyncConcurrentLfuBuilder<K, ScopedAsyncAtomicFactory<K, V>> inner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace BitFaster.Caching.Lfu.Builder
/// </summary>
/// <typeparam name="K">The type of the cache key.</typeparam>
/// <typeparam name="V">The type of the cache value.</typeparam>
public sealed class AtomicScopedConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, AtomicScopedConcurrentLfuBuilder<K, V>, IScopedCache<K, V>> where V : IDisposable
public sealed class AtomicScopedConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, AtomicScopedConcurrentLfuBuilder<K, V>, IScopedCache<K, V>>
where K : notnull
where V : IDisposable
{
private readonly ConcurrentLfuBuilder<K, ScopedAtomicFactory<K, V>> inner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace BitFaster.Caching.Lfu.Builder
/// </summary>
/// <typeparam name="K">The type of the cache key.</typeparam>
/// <typeparam name="V">The type of the cache value.</typeparam>
public sealed class ScopedAsyncConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, ScopedAsyncConcurrentLfuBuilder<K, V>, IScopedAsyncCache<K, V>> where V : IDisposable
public sealed class ScopedAsyncConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, ScopedAsyncConcurrentLfuBuilder<K, V>, IScopedAsyncCache<K, V>>
where K : notnull
where V : IDisposable
{
private readonly AsyncConcurrentLfuBuilder<K, Scoped<V>> inner;

Expand Down
5 changes: 4 additions & 1 deletion BitFaster.Caching/Lfu/Builder/ScopedConcurrentLfuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace BitFaster.Caching.Lfu.Builder
/// <typeparam name="K">The type of the cache key.</typeparam>
/// <typeparam name="V">The type of the cache value.</typeparam>
/// <typeparam name="W">The type of the wrapped cache value.</typeparam>
public sealed class ScopedConcurrentLfuBuilder<K, V, W> : LfuBuilderBase<K, V, ScopedConcurrentLfuBuilder<K, V, W>, IScopedCache<K, V>> where V : IDisposable where W : IScoped<V>
public sealed class ScopedConcurrentLfuBuilder<K, V, W> : LfuBuilderBase<K, V, ScopedConcurrentLfuBuilder<K, V, W>, IScopedCache<K, V>>
where K : notnull
where V : IDisposable
where W : IScoped<V>
{
private readonly ConcurrentLfuBuilder<K, W> inner;

Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lfu/ConcurrentLfu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace BitFaster.Caching.Lfu
[DebuggerTypeProxy(typeof(ConcurrentLfu<,>.LfuDebugView<>))]
[DebuggerDisplay("Count = {Count}/{Capacity}")]
public sealed class ConcurrentLfu<K, V> : ICache<K, V>, IAsyncCache<K, V>, IBoundedPolicy
where K : notnull
{
// Note: for performance reasons this is a mutable struct, it cannot be readonly.
private ConcurrentLfuCore<K, V, AccessOrderNode<K, V>, AccessOrderPolicy<K, V>> core;
Expand Down
1 change: 1 addition & 0 deletions BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace BitFaster.Caching.Lfu
/// <typeparam name="K">The type of keys in the cache.</typeparam>
/// <typeparam name="V">The type of values in the cache.</typeparam>
public sealed class ConcurrentLfuBuilder<K, V> : LfuBuilderBase<K, V, ConcurrentLfuBuilder<K, V>, ICache<K, V>>
where K : notnull
{
/// <summary>
/// Creates a ConcurrentLfuBuilder. Chain method calls onto ConcurrentLfuBuilder to configure the cache then call Build to create a cache instance.
Expand Down
Loading