Skip to content

Commit a140736

Browse files
authored
docs (#240)
* docs * docs
1 parent 1ec0ef2 commit a140736

File tree

63 files changed

+591
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+591
-190
lines changed

BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ private void VerifyHits(int iterations, int minSamples)
848848
private void LogLru()
849849
{
850850
#if DEBUG
851-
this.output.WriteLine(cache.FormatLruString());
851+
this.output.WriteLine(cache.FormatLfuString());
852852
#endif
853853
}
854854

BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public sealed class AtomicFactoryAsyncCache<K, V> : IAsyncCache<K, V>
1212
private readonly ICache<K, AsyncAtomicFactory<K, V>> cache;
1313
private readonly Optional<ICacheEvents<K, V>> events;
1414

15+
/// <summary>
16+
/// Initializes a new instance of the AtomicFactoryAsyncCache class with the specified inner cache.
17+
/// </summary>
18+
/// <param name="cache">The decorated cache.</param>
1519
public AtomicFactoryAsyncCache(ICache<K, AsyncAtomicFactory<K, V>> cache)
1620
{
1721
if (cache == null)
@@ -31,32 +35,41 @@ public AtomicFactoryAsyncCache(ICache<K, AsyncAtomicFactory<K, V>> cache)
3135
}
3236
}
3337

38+
///<inheritdoc/>
3439
public int Count => cache.Count;
3540

41+
///<inheritdoc/>
3642
public Optional<ICacheMetrics> Metrics => cache.Metrics;
3743

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

47+
///<inheritdoc/>
4048
public ICollection<K> Keys => this.cache.Keys;
4149

50+
///<inheritdoc/>
4251
public CachePolicy Policy => this.cache.Policy;
4352

53+
///<inheritdoc/>
4454
public void AddOrUpdate(K key, V value)
4555
{
4656
cache.AddOrUpdate(key, new AsyncAtomicFactory<K, V>(value));
4757
}
4858

59+
///<inheritdoc/>
4960
public void Clear()
5061
{
5162
cache.Clear();
5263
}
5364

65+
///<inheritdoc/>
5466
public ValueTask<V> GetOrAddAsync(K key, Func<K, Task<V>> valueFactory)
5567
{
5668
var synchronized = cache.GetOrAdd(key, _ => new AsyncAtomicFactory<K, V>());
5769
return synchronized.GetValueAsync(key, valueFactory);
5870
}
5971

72+
///<inheritdoc/>
6073
public bool TryGet(K key, out V value)
6174
{
6275
AsyncAtomicFactory<K, V> output;
@@ -72,16 +85,19 @@ public bool TryGet(K key, out V value)
7285
return false;
7386
}
7487

88+
///<inheritdoc/>
7589
public bool TryRemove(K key)
7690
{
7791
return cache.TryRemove(key);
7892
}
7993

94+
///<inheritdoc/>
8095
public bool TryUpdate(K key, V value)
8196
{
8297
return cache.TryUpdate(key, new AsyncAtomicFactory<K, V>(value));
8398
}
8499

100+
///<inheritdoc/>
85101
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
86102
{
87103
foreach (var kvp in this.cache)

BitFaster.Caching/Atomic/AtomicFactoryCache.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,41 @@ public AtomicFactoryCache(ICache<K, AtomicFactory<K, V>> cache)
3030
}
3131
}
3232

33+
///<inheritdoc/>
3334
public int Count => this.cache.Count;
3435

36+
///<inheritdoc/>
3537
public Optional<ICacheMetrics> Metrics => this.cache.Metrics;
3638

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

42+
///<inheritdoc/>
3943
public ICollection<K> Keys => this.cache.Keys;
4044

45+
///<inheritdoc/>
4146
public CachePolicy Policy => this.cache.Policy;
4247

48+
///<inheritdoc/>
4349
public void AddOrUpdate(K key, V value)
4450
{
4551
this.cache.AddOrUpdate(key, new AtomicFactory<K, V>(value));
4652
}
4753

54+
///<inheritdoc/>
4855
public void Clear()
4956
{
5057
this.cache.Clear();
5158
}
5259

60+
///<inheritdoc/>
5361
public V GetOrAdd(K key, Func<K, V> valueFactory)
5462
{
5563
var atomicFactory = cache.GetOrAdd(key, _ => new AtomicFactory<K, V>());
5664
return atomicFactory.GetValue(key, valueFactory);
5765
}
5866

67+
///<inheritdoc/>
5968
public bool TryGet(K key, out V value)
6069
{
6170
AtomicFactory<K, V> output;
@@ -71,16 +80,19 @@ public bool TryGet(K key, out V value)
7180
return false;
7281
}
7382

83+
///<inheritdoc/>
7484
public bool TryRemove(K key)
7585
{
7686
return cache.TryRemove(key);
7787
}
7888

89+
///<inheritdoc/>
7990
public bool TryUpdate(K key, V value)
8091
{
8192
return cache.TryUpdate(key, new AtomicFactory<K, V>(value));
8293
}
8394

95+
///<inheritdoc/>
8496
public IEnumerator<KeyValuePair<K, V>> GetEnumerator()
8597
{
8698
foreach (var kvp in this.cache)

BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public sealed class AtomicFactoryScopedAsyncCache<K, V> : IScopedAsyncCache<K, V
1313
private readonly ICache<K, ScopedAsyncAtomicFactory<K, V>> cache;
1414
private readonly Optional<ICacheEvents<K, Scoped<V>>> events;
1515

16+
/// <summary>
17+
/// Initializes a new instance of the AtomicFactoryScopedAsyncCache class with the specified inner cache.
18+
/// </summary>
19+
/// <param name="cache">The decorated cache.</param>
1620
public AtomicFactoryScopedAsyncCache(ICache<K, ScopedAsyncAtomicFactory<K, V>> cache)
1721
{
1822
if (cache == null)
@@ -31,27 +35,34 @@ public AtomicFactoryScopedAsyncCache(ICache<K, ScopedAsyncAtomicFactory<K, V>> c
3135
}
3236
}
3337

38+
///<inheritdoc/>
3439
public int Count => this.cache.Count;
3540

41+
///<inheritdoc/>
3642
public Optional<ICacheMetrics> Metrics => this.cache.Metrics;
3743

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

47+
///<inheritdoc/>
4048
public CachePolicy Policy => this.cache.Policy;
4149

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

53+
///<inheritdoc/>
4554
public void AddOrUpdate(K key, V value)
4655
{
4756
this.cache.AddOrUpdate(key, new ScopedAsyncAtomicFactory<K, V>(value));
4857
}
4958

59+
///<inheritdoc/>
5060
public void Clear()
5161
{
5262
this.cache.Clear();
5363
}
5464

65+
///<inheritdoc/>
5566
public async ValueTask<Lifetime<V>> ScopedGetOrAddAsync(K key, Func<K, Task<Scoped<V>>> valueFactory)
5667
{
5768
int c = 0;
@@ -76,6 +87,7 @@ public async ValueTask<Lifetime<V>> ScopedGetOrAddAsync(K key, Func<K, Task<Scop
7687
}
7788
}
7889

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

105+
///<inheritdoc/>
93106
public bool TryRemove(K key)
94107
{
95108
return this.cache.TryRemove(key);
96109
}
97110

111+
///<inheritdoc/>
98112
public bool TryUpdate(K key, V value)
99113
{
100114
return this.cache.TryUpdate(key, new ScopedAsyncAtomicFactory<K, V>(value));
101115
}
102116

117+
///<inheritdoc/>
103118
public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator()
104119
{
105120
foreach (var kvp in this.cache)

BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public sealed class AtomicFactoryScopedCache<K, V> : IScopedCache<K, V> where V
1212
private readonly ICache<K, ScopedAtomicFactory<K, V>> cache;
1313
private readonly Optional<ICacheEvents<K, Scoped<V>>> events;
1414

15+
/// <summary>
16+
/// Initializes a new instance of the AtomicFactoryScopedCache class with the specified inner cache.
17+
/// </summary>
18+
/// <param name="cache">The decorated cache.</param>
1519
public AtomicFactoryScopedCache(ICache<K, ScopedAtomicFactory<K, V>> cache)
1620
{
1721
if (cache == null)
@@ -31,27 +35,34 @@ public AtomicFactoryScopedCache(ICache<K, ScopedAtomicFactory<K, V>> cache)
3135
}
3236
}
3337

38+
///<inheritdoc/>
3439
public int Count => this.cache.Count;
3540

41+
///<inheritdoc/>
3642
public Optional<ICacheMetrics> Metrics => this.cache.Metrics;
3743

44+
///<inheritdoc/>
3845
public Optional<ICacheEvents<K, Scoped<V>>> Events => events;
3946

47+
///<inheritdoc/>
4048
public CachePolicy Policy => this.cache.Policy;
4149

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

53+
///<inheritdoc/>
4554
public void AddOrUpdate(K key, V value)
4655
{
4756
this.cache.AddOrUpdate(key, new ScopedAtomicFactory<K, V>(value));
4857
}
4958

59+
///<inheritdoc/>
5060
public void Clear()
5161
{
5262
this.cache.Clear();
5363
}
5464

65+
///<inheritdoc/>
5566
public Lifetime<V> ScopedGetOrAdd(K key, Func<K, Scoped<V>> valueFactory)
5667
{
5768
int c = 0;
@@ -74,6 +85,7 @@ public Lifetime<V> ScopedGetOrAdd(K key, Func<K, Scoped<V>> valueFactory)
7485
}
7586
}
7687

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

103+
///<inheritdoc/>
91104
public bool TryRemove(K key)
92105
{
93106
return this.cache.TryRemove(key);
94107
}
95108

109+
///<inheritdoc/>
96110
public bool TryUpdate(K key, V value)
97111
{
98112
return this.cache.TryUpdate(key, new ScopedAtomicFactory<K, V>(value));
99113
}
100114

115+
///<inheritdoc/>
101116
public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator()
102117
{
103118
foreach (var kvp in this.cache)
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
1+

52
namespace BitFaster.Caching.Buffers
63
{
4+
/// <summary>
5+
/// Specifies the status of buffer operations.
6+
/// </summary>
77
public enum BufferStatus
88
{
9+
/// <summary>
10+
/// The buffer is full.
11+
/// </summary>
912
Full,
13+
14+
/// <summary>
15+
/// The buffer is empty.
16+
/// </summary>
1017
Empty,
18+
19+
/// <summary>
20+
/// The buffer operation succeeded.
21+
/// </summary>
1122
Success,
23+
24+
/// <summary>
25+
/// The buffer operation was contended.
26+
/// </summary>
1227
Contended,
1328
}
1429
}

BitFaster.Caching/Buffers/PaddedHeadAndTail.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Drawing;
1+
using System.Diagnostics;
52
using System.Runtime.InteropServices;
6-
using System.Text;
73

84
namespace BitFaster.Caching.Buffers
95
{

BitFaster.Caching/Buffers/StripedBufferSize.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
namespace BitFaster.Caching.Buffers
44
{
5+
/// <summary>
6+
/// Represents the size of a striped buffer.
7+
/// </summary>
58
public sealed class StripedBufferSize
69
{
10+
/// <summary>
11+
/// Initializes a new instance of the StripedBufferSize class with the specified buffer size and stripe count.
12+
/// </summary>
13+
/// <param name="bufferSize">The size of each striped buffer.</param>
14+
/// <param name="stripeCount">The number of stripes.</param>
715
public StripedBufferSize(int bufferSize, int stripeCount)
816
{
917
if (bufferSize < 1)
@@ -20,8 +28,14 @@ public StripedBufferSize(int bufferSize, int stripeCount)
2028
StripeCount = BitOps.CeilingPowerOfTwo(stripeCount);
2129
}
2230

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

36+
/// <summary>
37+
/// The number of stripes.
38+
/// </summary>
2539
public int StripeCount { get; }
2640
}
2741
}

0 commit comments

Comments
 (0)