Skip to content
Merged

docs #240

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
2 changes: 1 addition & 1 deletion BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ private void VerifyHits(int iterations, int minSamples)
private void LogLru()
{
#if DEBUG
this.output.WriteLine(cache.FormatLruString());
this.output.WriteLine(cache.FormatLfuString());
#endif
}

Expand Down
16 changes: 16 additions & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public sealed class AtomicFactoryAsyncCache<K, V> : IAsyncCache<K, V>
private readonly ICache<K, AsyncAtomicFactory<K, V>> cache;
private readonly Optional<ICacheEvents<K, V>> events;

/// <summary>
/// Initializes a new instance of the AtomicFactoryAsyncCache class with the specified inner cache.
/// </summary>
/// <param name="cache">The decorated cache.</param>
public AtomicFactoryAsyncCache(ICache<K, AsyncAtomicFactory<K, V>> cache)
{
if (cache == null)
Expand All @@ -31,32 +35,41 @@ public AtomicFactoryAsyncCache(ICache<K, AsyncAtomicFactory<K, V>> cache)
}
}

///<inheritdoc/>
public int Count => cache.Count;

///<inheritdoc/>
public Optional<ICacheMetrics> Metrics => cache.Metrics;

///<inheritdoc/>
public Optional<ICacheEvents<K, V>> Events => this.events;

///<inheritdoc/>
public ICollection<K> Keys => this.cache.Keys;

///<inheritdoc/>
public CachePolicy Policy => this.cache.Policy;

///<inheritdoc/>
public void AddOrUpdate(K key, V value)
{
cache.AddOrUpdate(key, new AsyncAtomicFactory<K, V>(value));
}

///<inheritdoc/>
public void Clear()
{
cache.Clear();
}

///<inheritdoc/>
public ValueTask<V> GetOrAddAsync(K key, Func<K, Task<V>> valueFactory)
{
var synchronized = cache.GetOrAdd(key, _ => new AsyncAtomicFactory<K, V>());
return synchronized.GetValueAsync(key, valueFactory);
}

///<inheritdoc/>
public bool TryGet(K key, out V value)
{
AsyncAtomicFactory<K, V> output;
Expand All @@ -72,16 +85,19 @@ public bool TryGet(K key, out V value)
return false;
}

///<inheritdoc/>
public bool TryRemove(K key)
{
return cache.TryRemove(key);
}

///<inheritdoc/>
public bool TryUpdate(K key, V value)
{
return cache.TryUpdate(key, new AsyncAtomicFactory<K, V>(value));
}

///<inheritdoc/>
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
{
foreach (var kvp in this.cache)
Expand Down
12 changes: 12 additions & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,41 @@ public AtomicFactoryCache(ICache<K, AtomicFactory<K, V>> cache)
}
}

///<inheritdoc/>
public int Count => this.cache.Count;

///<inheritdoc/>
public Optional<ICacheMetrics> Metrics => this.cache.Metrics;

///<inheritdoc/>
public Optional<ICacheEvents<K, V>> Events => this.events;

///<inheritdoc/>
public ICollection<K> Keys => this.cache.Keys;

///<inheritdoc/>
public CachePolicy Policy => this.cache.Policy;

///<inheritdoc/>
public void AddOrUpdate(K key, V value)
{
this.cache.AddOrUpdate(key, new AtomicFactory<K, V>(value));
}

///<inheritdoc/>
public void Clear()
{
this.cache.Clear();
}

///<inheritdoc/>
public V GetOrAdd(K key, Func<K, V> valueFactory)
{
var atomicFactory = cache.GetOrAdd(key, _ => new AtomicFactory<K, V>());
return atomicFactory.GetValue(key, valueFactory);
}

///<inheritdoc/>
public bool TryGet(K key, out V value)
{
AtomicFactory<K, V> output;
Expand All @@ -71,16 +80,19 @@ public bool TryGet(K key, out V value)
return false;
}

///<inheritdoc/>
public bool TryRemove(K key)
{
return cache.TryRemove(key);
}

///<inheritdoc/>
public bool TryUpdate(K key, V value)
{
return cache.TryUpdate(key, new AtomicFactory<K, V>(value));
}

///<inheritdoc/>
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
{
foreach (var kvp in this.cache)
Expand Down
15 changes: 15 additions & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public sealed class AtomicFactoryScopedAsyncCache<K, V> : IScopedAsyncCache<K, V
private readonly ICache<K, ScopedAsyncAtomicFactory<K, V>> cache;
private readonly Optional<ICacheEvents<K, Scoped<V>>> events;

/// <summary>
/// Initializes a new instance of the AtomicFactoryScopedAsyncCache class with the specified inner cache.
/// </summary>
/// <param name="cache">The decorated cache.</param>
public AtomicFactoryScopedAsyncCache(ICache<K, ScopedAsyncAtomicFactory<K, V>> cache)
{
if (cache == null)
Expand All @@ -31,27 +35,34 @@ public AtomicFactoryScopedAsyncCache(ICache<K, ScopedAsyncAtomicFactory<K, V>> c
}
}

///<inheritdoc/>
public int Count => this.cache.Count;

///<inheritdoc/>
public Optional<ICacheMetrics> Metrics => this.cache.Metrics;

///<inheritdoc/>
public Optional<ICacheEvents<K, Scoped<V>>> Events => this.events;

///<inheritdoc/>
public CachePolicy Policy => this.cache.Policy;

///<inheritdoc/>
public ICollection<K> Keys => this.cache.Keys;

///<inheritdoc/>
public void AddOrUpdate(K key, V value)
{
this.cache.AddOrUpdate(key, new ScopedAsyncAtomicFactory<K, V>(value));
}

///<inheritdoc/>
public void Clear()
{
this.cache.Clear();
}

///<inheritdoc/>
public async ValueTask<Lifetime<V>> ScopedGetOrAddAsync(K key, Func<K, Task<Scoped<V>>> valueFactory)
{
int c = 0;
Expand All @@ -76,6 +87,7 @@ public async ValueTask<Lifetime<V>> ScopedGetOrAddAsync(K key, Func<K, Task<Scop
}
}

///<inheritdoc/>
public bool ScopedTryGet(K key, out Lifetime<V> lifetime)
{
if (this.cache.TryGet(key, out var scope))
Expand All @@ -90,16 +102,19 @@ public bool ScopedTryGet(K key, out Lifetime<V> lifetime)
return false;
}

///<inheritdoc/>
public bool TryRemove(K key)
{
return this.cache.TryRemove(key);
}

///<inheritdoc/>
public bool TryUpdate(K key, V value)
{
return this.cache.TryUpdate(key, new ScopedAsyncAtomicFactory<K, V>(value));
}

///<inheritdoc/>
public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator()
{
foreach (var kvp in this.cache)
Expand Down
15 changes: 15 additions & 0 deletions BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public sealed class AtomicFactoryScopedCache<K, V> : IScopedCache<K, V> where V
private readonly ICache<K, ScopedAtomicFactory<K, V>> cache;
private readonly Optional<ICacheEvents<K, Scoped<V>>> events;

/// <summary>
/// Initializes a new instance of the AtomicFactoryScopedCache class with the specified inner cache.
/// </summary>
/// <param name="cache">The decorated cache.</param>
public AtomicFactoryScopedCache(ICache<K, ScopedAtomicFactory<K, V>> cache)
{
if (cache == null)
Expand All @@ -31,27 +35,34 @@ public AtomicFactoryScopedCache(ICache<K, ScopedAtomicFactory<K, V>> cache)
}
}

///<inheritdoc/>
public int Count => this.cache.Count;

///<inheritdoc/>
public Optional<ICacheMetrics> Metrics => this.cache.Metrics;

///<inheritdoc/>
public Optional<ICacheEvents<K, Scoped<V>>> Events => events;

///<inheritdoc/>
public CachePolicy Policy => this.cache.Policy;

///<inheritdoc/>
public ICollection<K> Keys => this.cache.Keys;

///<inheritdoc/>
public void AddOrUpdate(K key, V value)
{
this.cache.AddOrUpdate(key, new ScopedAtomicFactory<K, V>(value));
}

///<inheritdoc/>
public void Clear()
{
this.cache.Clear();
}

///<inheritdoc/>
public Lifetime<V> ScopedGetOrAdd(K key, Func<K, Scoped<V>> valueFactory)
{
int c = 0;
Expand All @@ -74,6 +85,7 @@ public Lifetime<V> ScopedGetOrAdd(K key, Func<K, Scoped<V>> valueFactory)
}
}

///<inheritdoc/>
public bool ScopedTryGet(K key, out Lifetime<V> lifetime)
{
if (this.cache.TryGet(key, out var scope))
Expand All @@ -88,16 +100,19 @@ public bool ScopedTryGet(K key, out Lifetime<V> lifetime)
return false;
}

///<inheritdoc/>
public bool TryRemove(K key)
{
return this.cache.TryRemove(key);
}

///<inheritdoc/>
public bool TryUpdate(K key, V value)
{
return this.cache.TryUpdate(key, new ScopedAtomicFactory<K, V>(value));
}

///<inheritdoc/>
public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator()
{
foreach (var kvp in this.cache)
Expand Down
23 changes: 19 additions & 4 deletions BitFaster.Caching/Buffers/BufferStatus.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;


namespace BitFaster.Caching.Buffers
{
/// <summary>
/// Specifies the status of buffer operations.
/// </summary>
public enum BufferStatus
{
/// <summary>
/// The buffer is full.
/// </summary>
Full,

/// <summary>
/// The buffer is empty.
/// </summary>
Empty,

/// <summary>
/// The buffer operation succeeded.
/// </summary>
Success,

/// <summary>
/// The buffer operation was contended.
/// </summary>
Contended,
}
}
6 changes: 1 addition & 5 deletions BitFaster.Caching/Buffers/PaddedHeadAndTail.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

namespace BitFaster.Caching.Buffers
{
Expand Down
14 changes: 14 additions & 0 deletions BitFaster.Caching/Buffers/StripedBufferSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

namespace BitFaster.Caching.Buffers
{
/// <summary>
/// Represents the size of a striped buffer.
/// </summary>
public sealed class StripedBufferSize
{
/// <summary>
/// Initializes a new instance of the StripedBufferSize class with the specified buffer size and stripe count.
/// </summary>
/// <param name="bufferSize">The size of each striped buffer.</param>
/// <param name="stripeCount">The number of stripes.</param>
public StripedBufferSize(int bufferSize, int stripeCount)
{
if (bufferSize < 1)
Expand All @@ -20,8 +28,14 @@ public StripedBufferSize(int bufferSize, int stripeCount)
StripeCount = BitOps.CeilingPowerOfTwo(stripeCount);
}

/// <summary>
/// The size of the buffer. Each stripe will be initialized with a buffer of this size.
/// </summary>
public int BufferSize { get; }

/// <summary>
/// The number of stripes.
/// </summary>
public int StripeCount { get; }
}
}
Loading