diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs index 082d67c5..49504d53 100644 --- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs @@ -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 } diff --git a/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs b/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs index abf4d24f..b1686c4e 100644 --- a/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs +++ b/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs @@ -12,6 +12,10 @@ public sealed class AtomicFactoryAsyncCache : IAsyncCache private readonly ICache> cache; private readonly Optional> events; + /// + /// Initializes a new instance of the AtomicFactoryAsyncCache class with the specified inner cache. + /// + /// The decorated cache. public AtomicFactoryAsyncCache(ICache> cache) { if (cache == null) @@ -31,32 +35,41 @@ public AtomicFactoryAsyncCache(ICache> cache) } } + /// public int Count => cache.Count; + /// public Optional Metrics => cache.Metrics; + /// public Optional> Events => this.events; + /// public ICollection Keys => this.cache.Keys; + /// public CachePolicy Policy => this.cache.Policy; + /// public void AddOrUpdate(K key, V value) { cache.AddOrUpdate(key, new AsyncAtomicFactory(value)); } + /// public void Clear() { cache.Clear(); } + /// public ValueTask GetOrAddAsync(K key, Func> valueFactory) { var synchronized = cache.GetOrAdd(key, _ => new AsyncAtomicFactory()); return synchronized.GetValueAsync(key, valueFactory); } + /// public bool TryGet(K key, out V value) { AsyncAtomicFactory output; @@ -72,16 +85,19 @@ public bool TryGet(K key, out V value) return false; } + /// public bool TryRemove(K key) { return cache.TryRemove(key); } + /// public bool TryUpdate(K key, V value) { return cache.TryUpdate(key, new AsyncAtomicFactory(value)); } + /// public IEnumerator> GetEnumerator() { foreach (var kvp in this.cache) diff --git a/BitFaster.Caching/Atomic/AtomicFactoryCache.cs b/BitFaster.Caching/Atomic/AtomicFactoryCache.cs index 255bdb3f..9fb08fd0 100644 --- a/BitFaster.Caching/Atomic/AtomicFactoryCache.cs +++ b/BitFaster.Caching/Atomic/AtomicFactoryCache.cs @@ -30,32 +30,41 @@ public AtomicFactoryCache(ICache> cache) } } + /// public int Count => this.cache.Count; + /// public Optional Metrics => this.cache.Metrics; + /// public Optional> Events => this.events; + /// public ICollection Keys => this.cache.Keys; + /// public CachePolicy Policy => this.cache.Policy; + /// public void AddOrUpdate(K key, V value) { this.cache.AddOrUpdate(key, new AtomicFactory(value)); } + /// public void Clear() { this.cache.Clear(); } + /// public V GetOrAdd(K key, Func valueFactory) { var atomicFactory = cache.GetOrAdd(key, _ => new AtomicFactory()); return atomicFactory.GetValue(key, valueFactory); } + /// public bool TryGet(K key, out V value) { AtomicFactory output; @@ -71,16 +80,19 @@ public bool TryGet(K key, out V value) return false; } + /// public bool TryRemove(K key) { return cache.TryRemove(key); } + /// public bool TryUpdate(K key, V value) { return cache.TryUpdate(key, new AtomicFactory(value)); } + /// public IEnumerator> GetEnumerator() { foreach (var kvp in this.cache) diff --git a/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs b/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs index 168a9816..c22a7b31 100644 --- a/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs +++ b/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs @@ -13,6 +13,10 @@ public sealed class AtomicFactoryScopedAsyncCache : IScopedAsyncCache> cache; private readonly Optional>> events; + /// + /// Initializes a new instance of the AtomicFactoryScopedAsyncCache class with the specified inner cache. + /// + /// The decorated cache. public AtomicFactoryScopedAsyncCache(ICache> cache) { if (cache == null) @@ -31,27 +35,34 @@ public AtomicFactoryScopedAsyncCache(ICache> c } } + /// public int Count => this.cache.Count; + /// public Optional Metrics => this.cache.Metrics; + /// public Optional>> Events => this.events; + /// public CachePolicy Policy => this.cache.Policy; /// public ICollection Keys => this.cache.Keys; + /// public void AddOrUpdate(K key, V value) { this.cache.AddOrUpdate(key, new ScopedAsyncAtomicFactory(value)); } + /// public void Clear() { this.cache.Clear(); } + /// public async ValueTask> ScopedGetOrAddAsync(K key, Func>> valueFactory) { int c = 0; @@ -76,6 +87,7 @@ public async ValueTask> ScopedGetOrAddAsync(K key, Func public bool ScopedTryGet(K key, out Lifetime lifetime) { if (this.cache.TryGet(key, out var scope)) @@ -90,16 +102,19 @@ public bool ScopedTryGet(K key, out Lifetime lifetime) return false; } + /// public bool TryRemove(K key) { return this.cache.TryRemove(key); } + /// public bool TryUpdate(K key, V value) { return this.cache.TryUpdate(key, new ScopedAsyncAtomicFactory(value)); } + /// public IEnumerator>> GetEnumerator() { foreach (var kvp in this.cache) diff --git a/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs b/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs index c61b4f02..42a78adc 100644 --- a/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs +++ b/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs @@ -12,6 +12,10 @@ public sealed class AtomicFactoryScopedCache : IScopedCache where V private readonly ICache> cache; private readonly Optional>> events; + /// + /// Initializes a new instance of the AtomicFactoryScopedCache class with the specified inner cache. + /// + /// The decorated cache. public AtomicFactoryScopedCache(ICache> cache) { if (cache == null) @@ -31,27 +35,34 @@ public AtomicFactoryScopedCache(ICache> cache) } } + /// public int Count => this.cache.Count; + /// public Optional Metrics => this.cache.Metrics; + /// public Optional>> Events => events; + /// public CachePolicy Policy => this.cache.Policy; /// public ICollection Keys => this.cache.Keys; + /// public void AddOrUpdate(K key, V value) { this.cache.AddOrUpdate(key, new ScopedAtomicFactory(value)); } + /// public void Clear() { this.cache.Clear(); } + /// public Lifetime ScopedGetOrAdd(K key, Func> valueFactory) { int c = 0; @@ -74,6 +85,7 @@ public Lifetime ScopedGetOrAdd(K key, Func> valueFactory) } } + /// public bool ScopedTryGet(K key, out Lifetime lifetime) { if (this.cache.TryGet(key, out var scope)) @@ -88,16 +100,19 @@ public bool ScopedTryGet(K key, out Lifetime lifetime) return false; } + /// public bool TryRemove(K key) { return this.cache.TryRemove(key); } + /// public bool TryUpdate(K key, V value) { return this.cache.TryUpdate(key, new ScopedAtomicFactory(value)); } + /// public IEnumerator>> GetEnumerator() { foreach (var kvp in this.cache) diff --git a/BitFaster.Caching/Buffers/BufferStatus.cs b/BitFaster.Caching/Buffers/BufferStatus.cs index e936cf16..cb0479a4 100644 --- a/BitFaster.Caching/Buffers/BufferStatus.cs +++ b/BitFaster.Caching/Buffers/BufferStatus.cs @@ -1,14 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Text; - + namespace BitFaster.Caching.Buffers { + /// + /// Specifies the status of buffer operations. + /// public enum BufferStatus { + /// + /// The buffer is full. + /// Full, + + /// + /// The buffer is empty. + /// Empty, + + /// + /// The buffer operation succeeded. + /// Success, + + /// + /// The buffer operation was contended. + /// Contended, } } diff --git a/BitFaster.Caching/Buffers/PaddedHeadAndTail.cs b/BitFaster.Caching/Buffers/PaddedHeadAndTail.cs index 742b6074..654626b1 100644 --- a/BitFaster.Caching/Buffers/PaddedHeadAndTail.cs +++ b/BitFaster.Caching/Buffers/PaddedHeadAndTail.cs @@ -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 { diff --git a/BitFaster.Caching/Buffers/StripedBufferSize.cs b/BitFaster.Caching/Buffers/StripedBufferSize.cs index 22fcacd5..a0f873f4 100644 --- a/BitFaster.Caching/Buffers/StripedBufferSize.cs +++ b/BitFaster.Caching/Buffers/StripedBufferSize.cs @@ -2,8 +2,16 @@ namespace BitFaster.Caching.Buffers { + /// + /// Represents the size of a striped buffer. + /// public sealed class StripedBufferSize { + /// + /// Initializes a new instance of the StripedBufferSize class with the specified buffer size and stripe count. + /// + /// The size of each striped buffer. + /// The number of stripes. public StripedBufferSize(int bufferSize, int stripeCount) { if (bufferSize < 1) @@ -20,8 +28,14 @@ public StripedBufferSize(int bufferSize, int stripeCount) StripeCount = BitOps.CeilingPowerOfTwo(stripeCount); } + /// + /// The size of the buffer. Each stripe will be initialized with a buffer of this size. + /// public int BufferSize { get; } + /// + /// The number of stripes. + /// public int StripeCount { get; } } } diff --git a/BitFaster.Caching/CacheEventProxyBase.cs b/BitFaster.Caching/CacheEventProxyBase.cs index f4966fc1..acd7b1f4 100644 --- a/BitFaster.Caching/CacheEventProxyBase.cs +++ b/BitFaster.Caching/CacheEventProxyBase.cs @@ -1,22 +1,30 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching { + /// + /// Represents a base class for converting cache events for decorated caches such that the inner cache wrapper + /// type can be hidden from the outer cache. + /// + /// The type of the key + /// The inner value type + /// The outer value type public abstract class CacheEventProxyBase : ICacheEvents { private readonly ICacheEvents events; private event EventHandler> itemRemovedProxy; + /// + /// Initializes a new instance of the CacheEventProxyBase class with the specified inner cache events. + /// + /// The inner cache events. public CacheEventProxyBase(ICacheEvents events) { this.events = events; } + /// public event EventHandler> ItemRemoved { add { this.Register(value); } @@ -44,6 +52,11 @@ private void OnItemRemoved(object sender, ItemRemovedEventArgs args) itemRemovedProxy(sender, TranslateOnRemoved(args)); } + /// + /// Translate the ItemRemovedEventArgs by converting the inner arg type to the outer arg type. + /// + /// The inner arg. + /// The translated arg. protected abstract ItemRemovedEventArgs TranslateOnRemoved(ItemRemovedEventArgs inner); } } diff --git a/BitFaster.Caching/CachePolicy.cs b/BitFaster.Caching/CachePolicy.cs index 75bc6313..91172ba3 100644 --- a/BitFaster.Caching/CachePolicy.cs +++ b/BitFaster.Caching/CachePolicy.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace BitFaster.Caching { /// @@ -12,6 +7,11 @@ namespace BitFaster.Caching /// public class CachePolicy { + /// + /// Initializes a new instance of the CachePolicy class with the specified eviction and expire after write policies. + /// + /// The eviction policy. + /// The expire after write policy. public CachePolicy(Optional eviction, Optional expireAfterWrite) { this.Eviction = eviction; diff --git a/BitFaster.Caching/ICacheEvents.cs b/BitFaster.Caching/ICacheEvents.cs index a4033ae0..18978f1b 100644 --- a/BitFaster.Caching/ICacheEvents.cs +++ b/BitFaster.Caching/ICacheEvents.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching { diff --git a/BitFaster.Caching/Lfu/Builder/AtomicAsyncConcurrentLfuBuilder.cs b/BitFaster.Caching/Lfu/Builder/AtomicAsyncConcurrentLfuBuilder.cs index a45beae3..d00f3215 100644 --- a/BitFaster.Caching/Lfu/Builder/AtomicAsyncConcurrentLfuBuilder.cs +++ b/BitFaster.Caching/Lfu/Builder/AtomicAsyncConcurrentLfuBuilder.cs @@ -15,6 +15,7 @@ internal AtomicAsyncConcurrentLfuBuilder(ConcurrentLfuBuilder public override IAsyncCache Build() { var level1 = inner.Build(); diff --git a/BitFaster.Caching/Lfu/Builder/AtomicConcurrentLfuBuilder.cs b/BitFaster.Caching/Lfu/Builder/AtomicConcurrentLfuBuilder.cs index bcd01ec6..c35bd110 100644 --- a/BitFaster.Caching/Lfu/Builder/AtomicConcurrentLfuBuilder.cs +++ b/BitFaster.Caching/Lfu/Builder/AtomicConcurrentLfuBuilder.cs @@ -15,6 +15,7 @@ internal AtomicConcurrentLfuBuilder(ConcurrentLfuBuilder> this.inner = inner; } + /// public override ICache Build() { var level1 = inner.Build(); diff --git a/BitFaster.Caching/Lfu/Builder/AtomicScopedConcurrentLfuBuilder.cs b/BitFaster.Caching/Lfu/Builder/AtomicScopedConcurrentLfuBuilder.cs index 4197620f..eb0dcc97 100644 --- a/BitFaster.Caching/Lfu/Builder/AtomicScopedConcurrentLfuBuilder.cs +++ b/BitFaster.Caching/Lfu/Builder/AtomicScopedConcurrentLfuBuilder.cs @@ -15,6 +15,7 @@ internal AtomicScopedConcurrentLfuBuilder(ConcurrentLfuBuilder public override IScopedCache Build() { var level1 = inner.Build() as ICache>; diff --git a/BitFaster.Caching/Lfu/Builder/LfuBuilderBase.cs b/BitFaster.Caching/Lfu/Builder/LfuBuilderBase.cs index e19b87e9..662cb103 100644 --- a/BitFaster.Caching/Lfu/Builder/LfuBuilderBase.cs +++ b/BitFaster.Caching/Lfu/Builder/LfuBuilderBase.cs @@ -1,15 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using BitFaster.Caching.Scheduler; namespace BitFaster.Caching.Lfu.Builder { + /// + /// Represents the base class to be extended by LFU builder implementations. + /// + /// The type of the key. + /// The type of the value. + /// The type of the builder. + /// The return type of the builder. public abstract class LfuBuilderBase where TBuilder : LfuBuilderBase { internal readonly LfuInfo info; - protected LfuBuilderBase(LfuInfo info) + internal LfuBuilderBase(LfuInfo info) { this.info = info; } @@ -63,7 +68,6 @@ public TBuilder WithKeyComparer(IEqualityComparer comparer) /// Use the specified buffer configuration. Smaller buffers consume less memory, larger buffers can /// increase concurrent throughput. /// - /// The buffer configuration to use. /// A ConcurrentLfuBuilder public TBuilder WithBufferConfiguration(LfuBufferSize bufferConfiguration) { diff --git a/BitFaster.Caching/Lfu/Builder/LfuInfo.cs b/BitFaster.Caching/Lfu/Builder/LfuInfo.cs index 1cfb489e..18201b6a 100644 --- a/BitFaster.Caching/Lfu/Builder/LfuInfo.cs +++ b/BitFaster.Caching/Lfu/Builder/LfuInfo.cs @@ -6,7 +6,7 @@ namespace BitFaster.Caching.Lfu.Builder { - public sealed class LfuInfo + internal sealed class LfuInfo { private LfuBufferSize bufferConfiguration; diff --git a/BitFaster.Caching/Lfu/ConcurrentLfu.cs b/BitFaster.Caching/Lfu/ConcurrentLfu.cs index 058bdd8e..624a8262 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfu.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfu.cs @@ -783,7 +783,11 @@ internal class CacheMetrics : ICacheMetrics } #if DEBUG - public string FormatLruString() + /// + /// Format the LFU as a string by converting all the keys to strings. + /// + /// The LFU formatted as a string. + public string FormatLfuString() { var sb = new StringBuilder(); diff --git a/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs b/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs index d5215f8b..d4913ddf 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs @@ -3,6 +3,19 @@ namespace BitFaster.Caching.Lfu { + /// + /// A builder of ICache and IScopedCache instances with the following configuration + /// settings: + /// - The maximum size. + /// - The concurrency level. + /// - The key comparer. + /// - The buffer sizes. + /// + /// The following features can be selected which change the underlying cache implementation: + /// - Scoped IDisposable values. + /// + /// The type of keys in the cache. + /// The type of values in the cache. public sealed class ConcurrentLfuBuilder : LfuBuilderBase, ICache> { /// @@ -18,6 +31,7 @@ internal ConcurrentLfuBuilder(LfuInfo info) { } + /// public override ICache Build() { return new ConcurrentLfu(info.ConcurrencyLevel, info.Capacity, info.Scheduler, info.KeyComparer, info.BufferConfiguration); diff --git a/BitFaster.Caching/Lfu/ConcurrentLfuBuilderExtensions.cs b/BitFaster.Caching/Lfu/ConcurrentLfuBuilderExtensions.cs index 1aaf1806..4ee1e69a 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfuBuilderExtensions.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfuBuilderExtensions.cs @@ -1,11 +1,12 @@ using System; -using System.Collections.Generic; -using System.Text; using BitFaster.Caching.Atomic; using BitFaster.Caching.Lfu.Builder; namespace BitFaster.Caching.Lfu { + /// + /// Extension methods to support building all cache variants. + /// public static class ConcurrentLfuBuilderExtensions { /// diff --git a/BitFaster.Caching/Lfu/LfuBufferSize.cs b/BitFaster.Caching/Lfu/LfuBufferSize.cs index a7c16c20..4f7f582c 100644 --- a/BitFaster.Caching/Lfu/LfuBufferSize.cs +++ b/BitFaster.Caching/Lfu/LfuBufferSize.cs @@ -4,12 +4,23 @@ namespace BitFaster.Caching.Lfu { + /// + /// Represents the read and write buffer sizes used to initialize ConcurrentLfu. + /// public class LfuBufferSize { + /// + /// The default buffer size. + /// public const int DefaultBufferSize = 128; private const int MaxWriteBufferTotalSize = 1024; + /// + /// Initializes a new instance of the LfuBufferSize class with the specified read and write buffer sizes. + /// + /// The read buffer size. + /// The write buffer size. public LfuBufferSize(StripedBufferSize readBufferSize, StripedBufferSize writeBufferSize) { Read = readBufferSize ?? throw new ArgumentNullException(nameof(readBufferSize)); diff --git a/BitFaster.Caching/Lfu/LfuCapacityPartition.cs b/BitFaster.Caching/Lfu/LfuCapacityPartition.cs index a49c1ecf..f98392d5 100644 --- a/BitFaster.Caching/Lfu/LfuCapacityPartition.cs +++ b/BitFaster.Caching/Lfu/LfuCapacityPartition.cs @@ -3,6 +3,9 @@ namespace BitFaster.Caching.Lfu { + /// + /// Represents the LFU capacity partition. Uses a hill climbing algorithm to optimze partition sizes over time. + /// [DebuggerDisplay("{Capacity} ({Window}/{Protected}/{Probation})")] public sealed class LfuCapacityPartition { @@ -28,24 +31,48 @@ public sealed class LfuCapacityPartition private const double MaxMainPercentage = 0.999d; private const double MinMainPercentage = 0.2d; + /// + /// Initializes a new instance of the LfuCapacityPartition class with the specified total capacity. + /// + /// The total capacity. public LfuCapacityPartition(int totalCapacity) { this.max = totalCapacity; (windowCapacity, protectedCapacity, probationCapacity) = ComputeQueueCapacity(totalCapacity, DefaultMainPercentage); - InitializeStepSize(totalCapacity); + InitializeStepSize(); previousHitRate = 1.0; } + /// + /// Gets the number of items permitted in the window LRU. + /// public int Window => this.windowCapacity; + /// + /// Gets the number of items permitted in the protected LRU. + /// public int Protected => this.protectedCapacity; + /// + /// Gets the number of items permitted in the probation LRU. + /// public int Probation => this.probationCapacity; + /// + /// Gets the total capacity. + /// public int Capacity => this.max; - // Apply changes to the ratio of window to main, window = recency-biased, main = frequency-biased. + + /// + /// Optimize the size of the window and main LRUs based on changes in hit rate. + /// + /// The cache metrics. + /// The number of cache requests to sample before attempting to optimize LRU sizes. + /// + /// window = recency-biased, main = frequency-biased. + /// public void OptimizePartitioning(ICacheMetrics metrics, int sampleThreshold) { long newHits = metrics.Hits; @@ -81,7 +108,7 @@ public void OptimizePartitioning(ICacheMetrics metrics, int sampleThreshold) (windowCapacity, protectedCapacity, probationCapacity) = ComputeQueueCapacity(max, mainRatio); } - private void InitializeStepSize(int cacheSize) + private void InitializeStepSize() { stepSize = HillClimberStepPercent; } diff --git a/BitFaster.Caching/Lfu/LfuNode.cs b/BitFaster.Caching/Lfu/LfuNode.cs index 29734ba5..40028176 100644 --- a/BitFaster.Caching/Lfu/LfuNode.cs +++ b/BitFaster.Caching/Lfu/LfuNode.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BitFaster.Caching.Lfu +namespace BitFaster.Caching.Lfu { internal sealed class LfuNode { @@ -55,7 +51,7 @@ internal void Invalidate() } } - public enum Position + internal enum Position { Window, Probation, diff --git a/BitFaster.Caching/Lru/Builder/AtomicAsyncConcurrentLruBuilder.cs b/BitFaster.Caching/Lru/Builder/AtomicAsyncConcurrentLruBuilder.cs index 9a97e3e7..ab1320c1 100644 --- a/BitFaster.Caching/Lru/Builder/AtomicAsyncConcurrentLruBuilder.cs +++ b/BitFaster.Caching/Lru/Builder/AtomicAsyncConcurrentLruBuilder.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BitFaster.Caching.Atomic; +using BitFaster.Caching.Atomic; namespace BitFaster.Caching.Lru.Builder { @@ -17,6 +12,7 @@ internal AtomicAsyncConcurrentLruBuilder(ConcurrentLruBuilder public override IAsyncCache Build() { var level1 = inner.Build(); diff --git a/BitFaster.Caching/Lru/Builder/AtomicConcurrentLruBuilder.cs b/BitFaster.Caching/Lru/Builder/AtomicConcurrentLruBuilder.cs index 703e0899..420dfdf0 100644 --- a/BitFaster.Caching/Lru/Builder/AtomicConcurrentLruBuilder.cs +++ b/BitFaster.Caching/Lru/Builder/AtomicConcurrentLruBuilder.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BitFaster.Caching.Atomic; +using BitFaster.Caching.Atomic; namespace BitFaster.Caching.Lru.Builder { @@ -17,6 +12,7 @@ internal AtomicConcurrentLruBuilder(ConcurrentLruBuilder> this.inner = inner; } + /// public override ICache Build() { var level1 = inner.Build(); diff --git a/BitFaster.Caching/Lru/Builder/AtomicScopedConcurrentLruBuilder.cs b/BitFaster.Caching/Lru/Builder/AtomicScopedConcurrentLruBuilder.cs index 6a33b094..f575c570 100644 --- a/BitFaster.Caching/Lru/Builder/AtomicScopedConcurrentLruBuilder.cs +++ b/BitFaster.Caching/Lru/Builder/AtomicScopedConcurrentLruBuilder.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using BitFaster.Caching.Atomic; namespace BitFaster.Caching.Lru.Builder @@ -17,6 +13,7 @@ internal AtomicScopedConcurrentLruBuilder(ConcurrentLruBuilder public override IScopedCache Build() { var level1 = inner.Build() as ICache>; diff --git a/BitFaster.Caching/Lru/Builder/LruBuilderBase.cs b/BitFaster.Caching/Lru/Builder/LruBuilderBase.cs index 5c1b0641..1d6ee379 100644 --- a/BitFaster.Caching/Lru/Builder/LruBuilderBase.cs +++ b/BitFaster.Caching/Lru/Builder/LruBuilderBase.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru.Builder { @@ -13,7 +10,7 @@ public abstract class LruBuilderBase where TBuilde { internal readonly LruInfo info; - protected LruBuilderBase(LruInfo info) + internal LruBuilderBase(LruInfo info) { this.info = info; } diff --git a/BitFaster.Caching/Lru/Builder/LruInfo.cs b/BitFaster.Caching/Lru/Builder/LruInfo.cs index b3156da4..6933ebdd 100644 --- a/BitFaster.Caching/Lru/Builder/LruInfo.cs +++ b/BitFaster.Caching/Lru/Builder/LruInfo.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru.Builder { - public sealed class LruInfo + internal sealed class LruInfo { public ICapacityPartition Capacity { get; set; } = new FavorWarmPartition(128); diff --git a/BitFaster.Caching/Lru/Builder/ScopedAsyncConcurrentLruBuilder.cs b/BitFaster.Caching/Lru/Builder/ScopedAsyncConcurrentLruBuilder.cs index f1952876..400da06e 100644 --- a/BitFaster.Caching/Lru/Builder/ScopedAsyncConcurrentLruBuilder.cs +++ b/BitFaster.Caching/Lru/Builder/ScopedAsyncConcurrentLruBuilder.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru.Builder { diff --git a/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs b/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs index ddd0e4cb..229a088e 100644 --- a/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs +++ b/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BitFaster.Caching.Atomic; namespace BitFaster.Caching.Lru.Builder { diff --git a/BitFaster.Caching/Lru/CapacityPartitionExtensions.cs b/BitFaster.Caching/Lru/CapacityPartitionExtensions.cs index 16a0f840..06d0a7ed 100644 --- a/BitFaster.Caching/Lru/CapacityPartitionExtensions.cs +++ b/BitFaster.Caching/Lru/CapacityPartitionExtensions.cs @@ -1,14 +1,17 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { + /// + /// Extension methods for ICapacityPartition. + /// public static class CapacityPartitionExtensions { + /// + /// Validates the specified capacity partition. + /// + /// The capacity partition to validate. + /// Any of the hot, warm or cold capacities is less than 1. public static void Validate(this ICapacityPartition capacity) { if (capacity.Cold < 1) diff --git a/BitFaster.Caching/Lru/ClassicLru.cs b/BitFaster.Caching/Lru/ClassicLru.cs index 8a36cebd..8d2abdeb 100644 --- a/BitFaster.Caching/Lru/ClassicLru.cs +++ b/BitFaster.Caching/Lru/ClassicLru.cs @@ -3,7 +3,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -27,11 +26,23 @@ public sealed class ClassicLru : ICache, IAsyncCache, IBounded private readonly CacheMetrics metrics = new CacheMetrics(); private readonly CachePolicy policy; + /// + /// Initializes a new instance of the ClassicLru class with the specified capacity. + /// + /// public ClassicLru(int capacity) : this(Defaults.ConcurrencyLevel, capacity, EqualityComparer.Default) { } + /// + /// Initializes a new instance of the ClassicLru class with the specified concurrencyLevel, capacity and equality comparer. + /// + /// The concurrency level. + /// The capacity. + /// The key comparer + /// + /// public ClassicLru(int concurrencyLevel, int capacity, IEqualityComparer comparer) { if (capacity < 3) @@ -58,8 +69,10 @@ public ClassicLru(int concurrencyLevel, int capacity, IEqualityComparer compa /// public Optional Metrics => new Optional(this.metrics); + /// public Optional> Events => Optional>.None(); + /// public CachePolicy Policy => this.policy; /// diff --git a/BitFaster.Caching/Lru/ConcurrentLru.cs b/BitFaster.Caching/Lru/ConcurrentLru.cs index 36886f65..13313707 100644 --- a/BitFaster.Caching/Lru/ConcurrentLru.cs +++ b/BitFaster.Caching/Lru/ConcurrentLru.cs @@ -20,11 +20,11 @@ public ConcurrentLru(int capacity) /// /// Initializes a new instance of the ConcurrentLru class that has the specified concurrency level, has the - /// specified initial capacity, and uses the specified IEqualityComparer. + /// specified initial capacity, and uses the specified IEqualityComparer. /// /// The estimated number of threads that will update the ConcurrentLru concurrently. /// The maximum number of elements that the ConcurrentLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. public ConcurrentLru(int concurrencyLevel, int capacity, IEqualityComparer comparer) : base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, default, default) { @@ -32,11 +32,11 @@ public ConcurrentLru(int concurrencyLevel, int capacity, IEqualityComparer co /// /// Initializes a new instance of the ConcurrentLru class that has the specified concurrency level, has the - /// specified initial capacity, and uses the specified IEqualityComparer. + /// specified initial capacity, and uses the specified IEqualityComparer. /// /// The estimated number of threads that will update the ConcurrentLru concurrently. /// The maximum number of elements that the ConcurrentLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. public ConcurrentLru(int concurrencyLevel, ICapacityPartition capacity, IEqualityComparer comparer) : base(concurrencyLevel, capacity, comparer, default, default) { diff --git a/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs b/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs index 69038488..9132ecbc 100644 --- a/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs +++ b/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs @@ -1,13 +1,12 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using BitFaster.Caching.Lru.Builder; using BitFaster.Caching.Atomic; namespace BitFaster.Caching.Lru { + /// + /// Extension methods to support building all cache variants. + /// public static class ConcurrentLruBuilderExtensions { /// diff --git a/BitFaster.Caching/Lru/ConcurrentTLru.cs b/BitFaster.Caching/Lru/ConcurrentTLru.cs index 58f94d37..829bdf6e 100644 --- a/BitFaster.Caching/Lru/ConcurrentTLru.cs +++ b/BitFaster.Caching/Lru/ConcurrentTLru.cs @@ -22,11 +22,11 @@ public ConcurrentTLru(int capacity, TimeSpan timeToLive) /// /// Initializes a new instance of the ConcurrentTLru class that has the specified concurrency level, has the - /// specified initial capacity, uses the specified IEqualityComparer, and has the specified time to live. + /// specified initial capacity, uses the specified IEqualityComparer, and has the specified time to live. /// /// The estimated number of threads that will update the ConcurrentTLru concurrently. /// The maximum number of elements that the ConcurrentTLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. /// The time to live for cached values. public ConcurrentTLru(int concurrencyLevel, int capacity, IEqualityComparer comparer, TimeSpan timeToLive) : base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, new TLruLongTicksPolicy(timeToLive), default) @@ -35,11 +35,11 @@ public ConcurrentTLru(int concurrencyLevel, int capacity, IEqualityComparer c /// /// Initializes a new instance of the ConcurrentTLru class that has the specified concurrency level, has the - /// specified initial capacity, uses the specified IEqualityComparer, and has the specified time to live. + /// specified initial capacity, uses the specified IEqualityComparer, and has the specified time to live. /// /// The estimated number of threads that will update the ConcurrentTLru concurrently. /// The maximum number of elements that the ConcurrentTLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. /// The time to live for cached values. public ConcurrentTLru(int concurrencyLevel, ICapacityPartition capacity, IEqualityComparer comparer, TimeSpan timeToLive) : base(concurrencyLevel, capacity, comparer, new TLruLongTicksPolicy(timeToLive), default) diff --git a/BitFaster.Caching/Lru/EqualCapacityPartition.cs b/BitFaster.Caching/Lru/EqualCapacityPartition.cs index 9417f879..9aaa5d8f 100644 --- a/BitFaster.Caching/Lru/EqualCapacityPartition.cs +++ b/BitFaster.Caching/Lru/EqualCapacityPartition.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { @@ -17,6 +13,10 @@ public class EqualCapacityPartition : ICapacityPartition private readonly int warmCapacity; private readonly int coldCapacity; + /// + /// Initializes a new instance of the EqualCapacityPartition class with the specified total capacity. + /// + /// The total capacity. public EqualCapacityPartition(int totalCapacity) { var (hot, warm, cold) = ComputeQueueCapacity(totalCapacity); @@ -25,10 +25,13 @@ public EqualCapacityPartition(int totalCapacity) this.coldCapacity = cold; } + /// public int Cold => this.coldCapacity; + /// public int Warm => this.warmCapacity; + /// public int Hot => this.hotCapacity; private static (int hot, int warm, int cold) ComputeQueueCapacity(int capacity) diff --git a/BitFaster.Caching/Lru/FastConcurrentLru.cs b/BitFaster.Caching/Lru/FastConcurrentLru.cs index 86c0b0f2..09662d54 100644 --- a/BitFaster.Caching/Lru/FastConcurrentLru.cs +++ b/BitFaster.Caching/Lru/FastConcurrentLru.cs @@ -20,11 +20,11 @@ public FastConcurrentLru(int capacity) /// /// Initializes a new instance of the FastConcurrentLru class that has the specified concurrency level, has the - /// specified initial capacity, and uses the specified IEqualityComparer. + /// specified initial capacity, and uses the specified IEqualityComparer. /// /// The estimated number of threads that will update the FastConcurrentLru concurrently. /// The maximum number of elements that the FastConcurrentLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. public FastConcurrentLru(int concurrencyLevel, int capacity, IEqualityComparer comparer) : base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, default, default) { @@ -32,11 +32,11 @@ public FastConcurrentLru(int concurrencyLevel, int capacity, IEqualityComparer /// Initializes a new instance of the FastConcurrentLru class that has the specified concurrency level, has the - /// specified initial capacity, and uses the specified IEqualityComparer. + /// specified initial capacity, and uses the specified IEqualityComparer. /// /// The estimated number of threads that will update the FastConcurrentLru concurrently. /// The maximum number of elements that the FastConcurrentLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. public FastConcurrentLru(int concurrencyLevel, ICapacityPartition capacity, IEqualityComparer comparer) : base(concurrencyLevel, capacity, comparer, default, default) { diff --git a/BitFaster.Caching/Lru/FastConcurrentTLru.cs b/BitFaster.Caching/Lru/FastConcurrentTLru.cs index d437d665..422dab5c 100644 --- a/BitFaster.Caching/Lru/FastConcurrentTLru.cs +++ b/BitFaster.Caching/Lru/FastConcurrentTLru.cs @@ -22,11 +22,11 @@ public FastConcurrentTLru(int capacity, TimeSpan timeToLive) /// /// Initializes a new instance of the FastConcurrentTLru class that has the specified concurrency level, has the - /// specified initial capacity, uses the specified IEqualityComparer, and has the specified time to live. + /// specified initial capacity, uses the specified IEqualityComparer, and has the specified time to live. /// /// The estimated number of threads that will update the FastConcurrentTLru concurrently. /// The maximum number of elements that the FastConcurrentTLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. /// The time to live for cached values. public FastConcurrentTLru(int concurrencyLevel, int capacity, IEqualityComparer comparer, TimeSpan timeToLive) : base(concurrencyLevel, new FavorWarmPartition(capacity), comparer, new TLruLongTicksPolicy(timeToLive), default) @@ -35,11 +35,12 @@ public FastConcurrentTLru(int concurrencyLevel, int capacity, IEqualityComparer< /// /// Initializes a new instance of the FastConcurrentLru class that has the specified concurrency level, has the - /// specified initial capacity, and uses the specified IEqualityComparer. + /// specified initial capacity, and uses the specified IEqualityComparer. /// /// The estimated number of threads that will update the FastConcurrentLru concurrently. /// The maximum number of elements that the FastConcurrentLru can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. + /// The time to live for cached values. public FastConcurrentTLru(int concurrencyLevel, ICapacityPartition capacity, IEqualityComparer comparer, TimeSpan timeToLive) : base(concurrencyLevel, capacity, comparer, new TLruLongTicksPolicy(timeToLive), default) { diff --git a/BitFaster.Caching/Lru/FavorWarmPartition.cs b/BitFaster.Caching/Lru/FavorWarmPartition.cs index 2ecc649f..5ceb82ee 100644 --- a/BitFaster.Caching/Lru/FavorWarmPartition.cs +++ b/BitFaster.Caching/Lru/FavorWarmPartition.cs @@ -14,15 +14,26 @@ public class FavorWarmPartition : ICapacityPartition private readonly int warmCapacity; private readonly int coldCapacity; - // Default to 80% capacity allocated to warm queue, 20% split equally for hot and cold. - // This favors frequently accessed items. + /// + /// Default to 80% capacity allocated to warm queue, 20% split equally for hot and cold. + /// This favors frequently accessed items. + /// public const double DefaultWarmRatio = 0.8; + /// + /// Initializes a new instance of the FavorWarmPartition class with the specified capacity and the default warm ratio. + /// + /// The total capacity. public FavorWarmPartition(int totalCapacity) : this(totalCapacity, DefaultWarmRatio) { } + /// + /// Initializes a new instance of the FavorWarmPartition class with the specified capacity and warm ratio. + /// + /// The total capacity. + /// The ratio of warm items to hot and cold items. public FavorWarmPartition(int totalCapacity, double warmRatio) { var (hot, warm, cold) = ComputeQueueCapacity(totalCapacity, warmRatio); @@ -31,10 +42,13 @@ public FavorWarmPartition(int totalCapacity, double warmRatio) this.coldCapacity = cold; } + /// public int Cold => this.coldCapacity; + /// public int Warm => this.warmCapacity; + /// public int Hot => this.hotCapacity; private static (int hot, int warm, int cold) ComputeQueueCapacity(int capacity, double warmRatio) diff --git a/BitFaster.Caching/Lru/IItemPolicy.cs b/BitFaster.Caching/Lru/IItemPolicy.cs index f36b7967..af6ebdb6 100644 --- a/BitFaster.Caching/Lru/IItemPolicy.cs +++ b/BitFaster.Caching/Lru/IItemPolicy.cs @@ -1,29 +1,72 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { + /// + /// Represents an LRU item policy. + /// + /// The type of the key. + /// The type of the value. + /// The type of the LRU item. public interface IItemPolicy where I : LruItem { + /// + /// Creates an LRU item. + /// + /// The item key. + /// The item value. + /// An LRU item. I CreateItem(K key, V value); + /// + /// Touch an item on read. + /// + /// The item to touch. void Touch(I item); + /// + /// Update an item. + /// + /// The item to update. void Update(I item); + /// + /// Determine whether an item should be discarded. + /// + /// The item to check. + /// true if the item should be discarded, otherwise false. bool ShouldDiscard(I item); + /// + /// Gets a value indicating whether this policy can discard items. + /// + /// true if the policy can discard items, otherwise false. bool CanDiscard(); + /// + /// Route a hot item. + /// + /// The item to route. + /// The destination for the specified item. ItemDestination RouteHot(I item); + /// + /// Route a warm item. + /// + /// The item to route. + /// The destination for the specified item. ItemDestination RouteWarm(I item); + /// + /// Route a cold item. + /// + /// The item to route. + /// The destination for the specified item. ItemDestination RouteCold(I item); + /// + /// The item time to live defined by the policy. + /// TimeSpan TimeToLive { get; } } } diff --git a/BitFaster.Caching/Lru/ITelemetryPolicy.cs b/BitFaster.Caching/Lru/ITelemetryPolicy.cs index 95793076..311c1ade 100644 --- a/BitFaster.Caching/Lru/ITelemetryPolicy.cs +++ b/BitFaster.Caching/Lru/ITelemetryPolicy.cs @@ -1,21 +1,42 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace BitFaster.Caching.Lru { + /// + /// Represents a telemetry policy. + /// + /// The type of the key. + /// The type of the value. public interface ITelemetryPolicy : ICacheMetrics, ICacheEvents { + /// + /// Increment the miss counter. + /// void IncrementMiss(); + /// + /// Increment the hit counter. + /// void IncrementHit(); + /// + /// Register the removal of an item. + /// + /// The key. + /// The value. + /// The reason for removal. void OnItemRemoved(K key, V value, ItemRemovedReason reason); + /// + /// Register the update of an item. + /// + /// The key. + /// The value. void OnItemUpdated(K key, V value); + /// + /// Set the event source for any events that are fired. + /// + /// The event source. void SetEventSource(object source); } } diff --git a/BitFaster.Caching/Lru/ItemDestination.cs b/BitFaster.Caching/Lru/ItemDestination.cs index 0741e246..9481ef56 100644 --- a/BitFaster.Caching/Lru/ItemDestination.cs +++ b/BitFaster.Caching/Lru/ItemDestination.cs @@ -1,15 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace BitFaster.Caching.Lru { + /// + /// Specifies the destination for routing LRU items. + /// public enum ItemDestination { + /// + /// Route to the warm queue. + /// Warm, + + /// + /// Route to the cold queue. + /// Cold, + + /// + /// Remove the item. + /// Remove } } diff --git a/BitFaster.Caching/Lru/LongTickCountLruItem.cs b/BitFaster.Caching/Lru/LongTickCountLruItem.cs index 8d182a6f..31de3feb 100644 --- a/BitFaster.Caching/Lru/LongTickCountLruItem.cs +++ b/BitFaster.Caching/Lru/LongTickCountLruItem.cs @@ -1,19 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace BitFaster.Caching.Lru { + /// + /// Represents an LRU item that also stores tick count. + /// + /// The type of the key. + /// The type of the value. public class LongTickCountLruItem : LruItem { + /// + /// Initializes a new instance of the LongTickCountLruItem class with the specified key and value. + /// + /// The key. + /// The value. + /// The tick count. public LongTickCountLruItem(K key, V value, long tickCount) : base(key, value) { this.TickCount = tickCount; } + /// + /// Gets or sets the tick count. + /// public long TickCount { get; set; } } } diff --git a/BitFaster.Caching/Lru/LruItem.cs b/BitFaster.Caching/Lru/LruItem.cs index 2c05ee7f..56944316 100644 --- a/BitFaster.Caching/Lru/LruItem.cs +++ b/BitFaster.Caching/Lru/LruItem.cs @@ -1,32 +1,49 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace BitFaster.Caching.Lru { + /// + /// Represents an LRU item. + /// + /// The type of the key. + /// The type of the value. public class LruItem { private volatile bool wasAccessed; private volatile bool wasRemoved; + /// + /// Initializes a new instance of the LruItem class with the specified key and value. + /// + /// The key. + /// The value. public LruItem(K k, V v) { this.Key = k; this.Value = v; } + /// + /// Gets the key. + /// public readonly K Key; + /// + /// Gets or sets the value. + /// public V Value { get; set; } + /// + /// Gets or sets a value indicating whether the item was accessed. + /// public bool WasAccessed { get => this.wasAccessed; set => this.wasAccessed = value; } + /// + /// Gets or sets a value indicating whether the item was removed. + /// public bool WasRemoved { get => this.wasRemoved; diff --git a/BitFaster.Caching/Lru/LruPolicy.cs b/BitFaster.Caching/Lru/LruPolicy.cs index 05b07850..5982b6b9 100644 --- a/BitFaster.Caching/Lru/LruPolicy.cs +++ b/BitFaster.Caching/Lru/LruPolicy.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { @@ -12,37 +8,44 @@ namespace BitFaster.Caching.Lru /// public readonly struct LruPolicy : IItemPolicy> { + /// public TimeSpan TimeToLive => Defaults.Infinite; + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public LruItem CreateItem(K key, V value) { return new LruItem(key, value); } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Touch(LruItem item) { item.WasAccessed = true; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(LruItem item) { } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ShouldDiscard(LruItem item) { return false; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool CanDiscard() { return false; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteHot(LruItem item) { @@ -54,6 +57,7 @@ public ItemDestination RouteHot(LruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteWarm(LruItem item) { @@ -65,6 +69,7 @@ public ItemDestination RouteWarm(LruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteCold(LruItem item) { diff --git a/BitFaster.Caching/Lru/NoTelemetryPolicy.cs b/BitFaster.Caching/Lru/NoTelemetryPolicy.cs index 5bd16826..4c62d951 100644 --- a/BitFaster.Caching/Lru/NoTelemetryPolicy.cs +++ b/BitFaster.Caching/Lru/NoTelemetryPolicy.cs @@ -1,26 +1,35 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { + /// + /// Represents a telemtry policy that does not count or have events (is disabled). + /// This enables use of the cache without telemetry where maximum performance is required. + /// + /// The type of the key. + /// The type of the value. public struct NoTelemetryPolicy : ITelemetryPolicy { + /// public double HitRatio => 0.0; + /// public long Total => 0; + /// public long Hits => 0; + /// public long Misses => 0; + /// public long Updated => 0; + /// public long Evicted => 0; + /// public event EventHandler> ItemRemoved { // no-op, nothing is registered @@ -28,26 +37,31 @@ public event EventHandler> ItemRemoved remove { } } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void IncrementMiss() { } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void IncrementHit() { } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void OnItemRemoved(K key, V value, ItemRemovedReason reason) { } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void OnItemUpdated(K key, V value) { } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetEventSource(object source) { diff --git a/BitFaster.Caching/Lru/TelemetryPolicy.cs b/BitFaster.Caching/Lru/TelemetryPolicy.cs index e5a3566c..11290d48 100644 --- a/BitFaster.Caching/Lru/TelemetryPolicy.cs +++ b/BitFaster.Caching/Lru/TelemetryPolicy.cs @@ -1,10 +1,14 @@ using System; using System.Diagnostics; -using System.Threading; using BitFaster.Caching.Concurrent; namespace BitFaster.Caching.Lru { + /// + /// Represents a telemetry policy with counters and events. + /// + /// The type of the Key + /// The type of the value [DebuggerDisplay("Hit = {Hits}, Miss = {Misses}, Upd = {Updated}, Evict = {Evicted}")] public struct TelemetryPolicy : ITelemetryPolicy { @@ -14,30 +18,40 @@ public struct TelemetryPolicy : ITelemetryPolicy private LongAdder updatedCount; private object eventSource; + /// public event EventHandler> ItemRemoved; + /// public double HitRatio => Total == 0 ? 0 : (double)Hits / (double)Total; + /// public long Total => this.hitCount.Sum() + this.missCount.Sum(); + /// public long Hits => this.hitCount.Sum(); + /// public long Misses => this.missCount.Sum(); + /// public long Evicted => this.evictedCount.Sum(); + /// public long Updated => this.updatedCount.Sum(); + /// public void IncrementMiss() { this.missCount.Increment(); } + /// public void IncrementHit() { this.hitCount.Increment(); } + /// public void OnItemRemoved(K key, V value, ItemRemovedReason reason) { if (reason == ItemRemovedReason.Evicted) @@ -49,11 +63,13 @@ public void OnItemRemoved(K key, V value, ItemRemovedReason reason) this.ItemRemoved?.Invoke(this.eventSource, new ItemRemovedEventArgs(key, value, reason)); } + /// public void OnItemUpdated(K key, V value) { this.updatedCount.Increment(); } + /// public void SetEventSource(object source) { this.hitCount = new LongAdder(); diff --git a/BitFaster.Caching/Lru/TickCountLruItem.cs b/BitFaster.Caching/Lru/TickCountLruItem.cs index 43eb06d3..3fae631a 100644 --- a/BitFaster.Caching/Lru/TickCountLruItem.cs +++ b/BitFaster.Caching/Lru/TickCountLruItem.cs @@ -1,19 +1,28 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { + /// + /// Represents an LRU item that also stores tick count. + /// + /// The type of the key. + /// The type of the value. public class TickCountLruItem : LruItem { + /// + /// Initializes a new instance of the TickCountLruItem class with the specified key and value. + /// + /// The key. + /// The value. public TickCountLruItem(K key, V value) : base(key, value) { this.TickCount = Environment.TickCount; } + /// + /// Gets or sets the tick count. + /// public int TickCount { get; set; } } } diff --git a/BitFaster.Caching/Lru/TimeStampedLruItem.cs b/BitFaster.Caching/Lru/TimeStampedLruItem.cs index 051aaa61..b05fc3c1 100644 --- a/BitFaster.Caching/Lru/TimeStampedLruItem.cs +++ b/BitFaster.Caching/Lru/TimeStampedLruItem.cs @@ -1,19 +1,28 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { + /// + /// Represents an LRU item that also stores the item time stamp. + /// + /// The type of the key. + /// The type of the value. public class TimeStampedLruItem : LruItem { + /// + /// Initializes a new instance of the TimeStampedLruItem class with the specified key and value. + /// + /// The key. + /// The value. public TimeStampedLruItem(K key, V value) : base(key, value) { this.TimeStamp = DateTime.UtcNow; } + /// + /// Gets or sets the time stamp. + /// public DateTime TimeStamp { get; set; } } } diff --git a/BitFaster.Caching/Lru/TlruDateTimePolicy.cs b/BitFaster.Caching/Lru/TlruDateTimePolicy.cs index 6191918e..effdab1f 100644 --- a/BitFaster.Caching/Lru/TlruDateTimePolicy.cs +++ b/BitFaster.Caching/Lru/TlruDateTimePolicy.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { @@ -15,31 +11,40 @@ namespace BitFaster.Caching.Lru { private readonly TimeSpan timeToLive; + /// public TimeSpan TimeToLive => timeToLive; + /// + /// Initializes a new instance of the TLruDateTimePolicy class with the specified time to live. + /// + /// The time to live. public TLruDateTimePolicy(TimeSpan timeToLive) { this.timeToLive = timeToLive; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public TimeStampedLruItem CreateItem(K key, V value) { return new TimeStampedLruItem(key, value); } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Touch(TimeStampedLruItem item) { item.WasAccessed = true; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(TimeStampedLruItem item) { item.TimeStamp = DateTime.UtcNow; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ShouldDiscard(TimeStampedLruItem item) { @@ -51,12 +56,14 @@ public bool ShouldDiscard(TimeStampedLruItem item) return false; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool CanDiscard() { return true; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteHot(TimeStampedLruItem item) { @@ -73,6 +80,7 @@ public ItemDestination RouteHot(TimeStampedLruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteWarm(TimeStampedLruItem item) { @@ -89,6 +97,7 @@ public ItemDestination RouteWarm(TimeStampedLruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteCold(TimeStampedLruItem item) { diff --git a/BitFaster.Caching/Lru/TlruLongTicksPolicy.cs b/BitFaster.Caching/Lru/TlruLongTicksPolicy.cs index 599fb99b..6440b14d 100644 --- a/BitFaster.Caching/Lru/TlruLongTicksPolicy.cs +++ b/BitFaster.Caching/Lru/TlruLongTicksPolicy.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { @@ -22,29 +18,37 @@ namespace BitFaster.Caching.Lru private static readonly double stopwatchAdjustmentFactor = Stopwatch.Frequency / (double)TimeSpan.TicksPerSecond; private readonly long timeToLive; + /// + /// Initializes a new instance of the TLruLongTicksPolicy class with the specified time to live. + /// + /// The time to live. public TLruLongTicksPolicy(TimeSpan timeToLive) { this.timeToLive = ToTicks(timeToLive); } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public LongTickCountLruItem CreateItem(K key, V value) { return new LongTickCountLruItem(key, value, Stopwatch.GetTimestamp()); } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Touch(LongTickCountLruItem item) { item.WasAccessed = true; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(LongTickCountLruItem item) { item.TickCount = Stopwatch.GetTimestamp(); } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ShouldDiscard(LongTickCountLruItem item) { @@ -56,12 +60,14 @@ public bool ShouldDiscard(LongTickCountLruItem item) return false; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool CanDiscard() { return true; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteHot(LongTickCountLruItem item) { @@ -78,6 +84,7 @@ public ItemDestination RouteHot(LongTickCountLruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteWarm(LongTickCountLruItem item) { @@ -94,6 +101,7 @@ public ItemDestination RouteWarm(LongTickCountLruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteCold(LongTickCountLruItem item) { @@ -110,13 +118,24 @@ public ItemDestination RouteCold(LongTickCountLruItem item) return ItemDestination.Remove; } + /// public TimeSpan TimeToLive => FromTicks(timeToLive); + /// + /// Convert from TimeSpan to ticks. + /// + /// The time represented as a TimeSpan. + /// The time represented as ticks. public static long ToTicks(TimeSpan timespan) { return (long)(timespan.Ticks * stopwatchAdjustmentFactor); } + /// + /// Convert from ticks to a TimeSpan. + /// + /// The time represented as ticks. + /// The time represented as a TimeSpan. public static TimeSpan FromTicks(long ticks) { return TimeSpan.FromTicks((long)(ticks / stopwatchAdjustmentFactor)); diff --git a/BitFaster.Caching/Lru/TlruTicksPolicy.cs b/BitFaster.Caching/Lru/TlruTicksPolicy.cs index 532fe8c1..e800cfa1 100644 --- a/BitFaster.Caching/Lru/TlruTicksPolicy.cs +++ b/BitFaster.Caching/Lru/TlruTicksPolicy.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Lru { @@ -20,31 +16,40 @@ namespace BitFaster.Caching.Lru { private readonly int timeToLive; + /// public TimeSpan TimeToLive => TimeSpan.FromMilliseconds(timeToLive); + /// + /// Initializes a new instance of the TLruTicksPolicy class with the specified time to live. + /// + /// The time to live. public TLruTicksPolicy(TimeSpan timeToLive) { this.timeToLive = (int)timeToLive.TotalMilliseconds; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public TickCountLruItem CreateItem(K key, V value) { return new TickCountLruItem(key, value); } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Touch(TickCountLruItem item) { item.WasAccessed = true; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(TickCountLruItem item) { item.TickCount = Environment.TickCount; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ShouldDiscard(TickCountLruItem item) { @@ -56,12 +61,14 @@ public bool ShouldDiscard(TickCountLruItem item) return false; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool CanDiscard() { return true; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteHot(TickCountLruItem item) { @@ -78,6 +85,7 @@ public ItemDestination RouteHot(TickCountLruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteWarm(TickCountLruItem item) { @@ -94,6 +102,7 @@ public ItemDestination RouteWarm(TickCountLruItem item) return ItemDestination.Cold; } + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public ItemDestination RouteCold(TickCountLruItem item) { diff --git a/BitFaster.Caching/Optional.cs b/BitFaster.Caching/Optional.cs index 34c92307..c00ad92f 100644 --- a/BitFaster.Caching/Optional.cs +++ b/BitFaster.Caching/Optional.cs @@ -11,10 +11,17 @@ public class Optional private readonly T value; private readonly bool hasValue; + /// + /// Initializes a new instance of the Optional class. + /// public Optional() { } + /// + /// Initializes a new instance of the Optional class with the specified value. + /// + /// The value. public Optional(T value) { this.value = value; @@ -22,19 +29,19 @@ public Optional(T value) } /// - /// Gets the value of the current Optional object if it has been assigned a valid underlying value. + /// Gets the value of the current Optional object if it has been assigned a valid underlying value. /// public T Value => this.value; /// - /// Gets a value indicating whether the current Optional object has a valid value of its underlying type. + /// Gets a value indicating whether the current Optional object has a valid value of its underlying type. /// public bool HasValue => this.hasValue; /// - /// Creates an empty Optional. + /// Creates an empty Optional. /// - /// An empty Optional. + /// An empty Optional. public static Optional None() { return new Optional(); diff --git a/BitFaster.Caching/ReferenceCount.cs b/BitFaster.Caching/ReferenceCount.cs index 71964d5b..d67a7314 100644 --- a/BitFaster.Caching/ReferenceCount.cs +++ b/BitFaster.Caching/ReferenceCount.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; namespace BitFaster.Caching { @@ -13,6 +12,11 @@ public class ReferenceCount : IEquatable> private readonly TValue value; private readonly int count; + /// + /// Initializes a new instance of the ReferenceCount class with the specified value. + /// Initial count is 1. + /// + /// public ReferenceCount(TValue value) { this.value = value; @@ -88,11 +92,23 @@ public override int GetHashCode() return hashCode; } + /// + /// Determines whether two ReferenceCount instances have the same value. + /// + /// The left ReferernceCount to compare, or null. + /// The right ReferernceCount to compare, or null. + /// true if the value of left is the same as the value of right; otherwise, false. public static bool operator ==(ReferenceCount left, ReferenceCount right) { return EqualityComparer>.Default.Equals(left, right); } + /// + /// Determines whether two ReferenceCount instances have different values. + /// + /// The left ReferernceCount to compare, or null. + /// The right ReferernceCount to compare, or null. + /// true if the value of left is different from the value of right; otherwise, false. public static bool operator !=(ReferenceCount left, ReferenceCount right) { return !(left == right); diff --git a/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs b/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs index 7bb1bbdc..cd6d74c6 100644 --- a/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs +++ b/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Runtime.Serialization; -using System.Text; using System.Threading; using System.Threading.Tasks; using BitFaster.Caching.Buffers; @@ -19,7 +16,11 @@ namespace BitFaster.Caching.Scheduler /// public sealed class BackgroundThreadScheduler : IScheduler, IDisposable { + /// + /// The maximum number of work items to store. + /// public const int MaxBacklog = 16; + private int count; private readonly CancellationTokenSource cts = new CancellationTokenSource(); private readonly SemaphoreSlim semaphore = new SemaphoreSlim(0, MaxBacklog); @@ -29,20 +30,28 @@ public sealed class BackgroundThreadScheduler : IScheduler, IDisposable TaskCompletionSource completion = new TaskCompletionSource(); + /// + /// Initializes a new instance of the BackgroundThreadScheduler class. + /// public BackgroundThreadScheduler() { // dedicated thread Task.Factory.StartNew(() => Background(), TaskCreationOptions.LongRunning); } + /// public Task Completion => completion.Task; + /// public bool IsBackground => true; + /// public long RunCount => count; + /// public Optional LastException => lastException; + /// public void Run(Action action) { if (work.TryAdd(action) == BufferStatus.Success) @@ -93,6 +102,9 @@ private async Task Background() completion.SetResult(true); } + /// + /// Terminate the background thread. + /// public void Dispose() { // prevent hang when cancel runs on the same thread diff --git a/BitFaster.Caching/Scheduler/ForegroundScheduler.cs b/BitFaster.Caching/Scheduler/ForegroundScheduler.cs index 70d4a233..4ead6f52 100644 --- a/BitFaster.Caching/Scheduler/ForegroundScheduler.cs +++ b/BitFaster.Caching/Scheduler/ForegroundScheduler.cs @@ -9,12 +9,16 @@ public sealed class ForegroundScheduler : IScheduler { private long count; + /// public bool IsBackground => false; + /// public long RunCount => count; + /// public Optional LastException => Optional.None(); + /// public void Run(Action action) { count++; diff --git a/BitFaster.Caching/Scheduler/IScheduler.cs b/BitFaster.Caching/Scheduler/IScheduler.cs index e58da3ff..2b60ea20 100644 --- a/BitFaster.Caching/Scheduler/IScheduler.cs +++ b/BitFaster.Caching/Scheduler/IScheduler.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Scheduler { @@ -10,6 +7,9 @@ namespace BitFaster.Caching.Scheduler /// public interface IScheduler { + /// + /// Gets a value indicating whether this scheduler runs tasks in the background. + /// bool IsBackground { get; } /// diff --git a/BitFaster.Caching/Scheduler/NullScheduler.cs b/BitFaster.Caching/Scheduler/NullScheduler.cs index c77d6b81..b84cf3d4 100644 --- a/BitFaster.Caching/Scheduler/NullScheduler.cs +++ b/BitFaster.Caching/Scheduler/NullScheduler.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching.Scheduler { @@ -12,12 +9,16 @@ public sealed class NullScheduler : IScheduler { private long count; + /// public bool IsBackground => false; + /// public long RunCount => count; + /// public Optional LastException => Optional.None(); + /// public void Run(Action action) { count++; diff --git a/BitFaster.Caching/Scheduler/ThreadPoolScheduler.cs b/BitFaster.Caching/Scheduler/ThreadPoolScheduler.cs index 9f08e665..075f5922 100644 --- a/BitFaster.Caching/Scheduler/ThreadPoolScheduler.cs +++ b/BitFaster.Caching/Scheduler/ThreadPoolScheduler.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; using System.Threading.Tasks; namespace BitFaster.Caching.Scheduler @@ -14,12 +11,16 @@ public sealed class ThreadPoolScheduler : IScheduler private long count; private Optional lastException = Optional.None(); + /// public bool IsBackground => true; + /// public long RunCount => count; + /// public Optional LastException => lastException; + /// public void Run(Action action) { count++; diff --git a/BitFaster.Caching/Scoped.cs b/BitFaster.Caching/Scoped.cs index 31705583..6d62bbc0 100644 --- a/BitFaster.Caching/Scoped.cs +++ b/BitFaster.Caching/Scoped.cs @@ -27,6 +27,9 @@ public Scoped(T value) this.refCount = new ReferenceCount(value); } + /// + /// Gets a value indicating whether the scope is disposed. + /// public bool IsDisposed => isDisposed; /// diff --git a/BitFaster.Caching/ScopedAsyncCache.cs b/BitFaster.Caching/ScopedAsyncCache.cs index c2362dcf..0df0709b 100644 --- a/BitFaster.Caching/ScopedAsyncCache.cs +++ b/BitFaster.Caching/ScopedAsyncCache.cs @@ -19,6 +19,11 @@ public sealed class ScopedAsyncCache : IScopedAsyncCache where V : I { private readonly IAsyncCache> cache; + /// + /// Initializes a new instance of the ScopedAsyncCache class with the specified inner cache. + /// + /// The decorated cache. + /// public ScopedAsyncCache(IAsyncCache> cache) { if (cache == null) @@ -106,6 +111,7 @@ public bool TryUpdate(K key, V value) return this.cache.TryUpdate(key, new Scoped(value)); } + /// public IEnumerator>> GetEnumerator() { foreach (var kvp in this.cache) diff --git a/BitFaster.Caching/ScopedCache.cs b/BitFaster.Caching/ScopedCache.cs index b3ac8fa0..e6713d49 100644 --- a/BitFaster.Caching/ScopedCache.cs +++ b/BitFaster.Caching/ScopedCache.cs @@ -18,6 +18,10 @@ public sealed class ScopedCache : IScopedCache where V : IDisposable { private readonly ICache> cache; + /// + /// Initializes a new instance of the ScopedCache class with the specified inner cache. + /// + /// The decorated cache. public ScopedCache(ICache> cache) { if (cache == null) @@ -105,6 +109,7 @@ public bool TryUpdate(K key, V value) return this.cache.TryUpdate(key, new Scoped(value)); } + /// public IEnumerator>> GetEnumerator() { foreach (var kvp in this.cache) diff --git a/BitFaster.Caching/SingletonCache.cs b/BitFaster.Caching/SingletonCache.cs index 9243a175..93fd330c 100644 --- a/BitFaster.Caching/SingletonCache.cs +++ b/BitFaster.Caching/SingletonCache.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BitFaster.Caching { @@ -29,11 +26,11 @@ public SingletonCache() /// /// Initializes a new instance of the SingletonCache that has the specified concurrency level, has the - /// specified initial capacity, and uses the specified IEqualityComparer. + /// specified initial capacity, and uses the specified IEqualityComparer. /// /// The estimated number of threads that will update the SingletonCache concurrently. /// The initial number of elements that the SingletonCache can contain. - /// The IEqualityComparer implementation to use when comparing keys. + /// The IEqualityComparer implementation to use when comparing keys. public SingletonCache(int concurrencyLevel, int capacity, IEqualityComparer comparer) { this.cache = new ConcurrentDictionary>(concurrencyLevel, capacity, comparer); diff --git a/BitFaster.Caching/SingletonCacheExtensions.cs b/BitFaster.Caching/SingletonCacheExtensions.cs index 4dc8b2d1..d746c971 100644 --- a/BitFaster.Caching/SingletonCacheExtensions.cs +++ b/BitFaster.Caching/SingletonCacheExtensions.cs @@ -1,15 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Text; - + namespace BitFaster.Caching { + /// + /// Extension methods for the SingletonCache class. + /// public static class SingletonCacheExtensions { /// /// Acquire a singleton value for the specified key. The lifetime guarantees the value is alive and is a singleton /// for the given key until the lifetime is disposed. /// + /// The cache to use. /// The key of the item /// A value lifetime public static Lifetime Acquire(this SingletonCache cache, TKey key)