From a91f518feedf65d8450d6847c67d0344495478b0 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Thu, 8 Jan 2026 16:51:56 -0800 Subject: [PATCH] format --- .../DataStructureBenchmarks.cs | 6 +-- BitFaster.Caching.Benchmarks/DisposerBench.cs | 2 +- .../Lfu/CmSketchNoPin.cs | 2 +- .../Lfu/LfuJustGetOrAdd.cs | 12 ++--- .../Lfu/SketchFrequency.cs | 2 +- .../Lru/LruCycleBench.cs | 4 +- .../Lru/LruJustGetOrAdd.cs | 16 +++---- .../Lru/LruJustGetOrAddGuid.cs | 16 +++---- .../Lru/LruMultiGet.cs | 10 ++--- .../ValueFactoryBenchmarks.cs | 4 +- BitFaster.Caching.HitRateAnalysis/Analysis.cs | 2 +- .../Arc/ArcDataFile.cs | 44 +++++++++---------- .../Arc/Runner.cs | 2 +- .../Glimpse/DataFile.cs | 2 +- BitFaster.Caching.HitRateAnalysis/PlotExt.cs | 2 +- .../Wikibench/WikiBenchFile.cs | 20 ++++----- .../CacheFactory.cs | 6 +-- .../Exporter.cs | 6 +-- .../ParallelBenchmark.cs | 4 +- .../Runner.cs | 4 +- .../ThreadPoolInspector.cs | 2 +- .../ThroughputBenchmark.cs | 6 +-- .../DurationTests.cs | 4 +- .../Atomic/AtomicFactoryAsyncCacheTests.cs | 6 +-- .../Atomic/AtomicFactoryCacheTests.cs | 4 +- .../AtomicFactoryScopedAsyncCacheTests.cs | 4 +- .../Atomic/AtomicFactoryScopedCacheTests.cs | 4 +- .../Atomic/AtomicFactoryTests.cs | 2 +- .../ConcurrentDictionaryExtensionTests.cs | 2 +- .../Buffers/MpmcBoundedBufferSoakTests.cs | 2 +- .../Buffers/MpscBoundedBufferSoakTests.cs | 6 +-- .../Buffers/StripedMpscBufferTests.cs | 4 +- .../CacheEventProxyBaseTests.cs | 2 +- BitFaster.Caching.UnitTests/CacheTests.cs | 2 +- BitFaster.Caching.UnitTests/Disposable.cs | 2 +- .../ExpireAfterAccessTests.cs | 4 +- .../ExpireAfterWriteTests.cs | 2 +- BitFaster.Caching.UnitTests/Intrinsics.cs | 6 +-- .../Lfu/ConcurrentLfuCoreTests.cs | 6 +-- .../Lfu/ConcurrentLfuSoakTests.cs | 35 +++++++++------ .../Lfu/ConcurrentLfuTests.cs | 12 ++--- .../Lfu/ConcurrentTLfuSoakTests.cs | 3 +- .../Lfu/ConcurrentTLfuTests.cs | 6 +-- .../Lfu/LfuNodeSoakTest.cs | 12 ++--- .../Lfu/NodeMemoryLayoutDumps.cs | 2 +- .../Lfu/TimerWheelTests.cs | 2 +- .../Lru/AfterAccessPolicyTests.cs | 6 +-- .../Lru/CacheExtTests.cs | 4 +- .../Lru/ClassicLruTests.cs | 12 ++--- .../Lru/ConcurrentLruAfterAccessTests.cs | 6 +-- .../Lru/ConcurrentLruBuilderTests.cs | 6 +-- .../Lru/ConcurrentLruSoakTests.cs | 43 +++++++++++------- .../Lru/ConcurrentLruTests.cs | 32 +++++++------- .../Lru/ConcurrentTLruSoakTests.cs | 3 +- .../Lru/ConcurrentTLruTests.cs | 8 ++-- .../Lru/DiscretePolicyTests.cs | 6 +-- .../Lru/FastConcurrentLruTests.cs | 6 +-- .../Lru/FastConcurrentTLruTests.cs | 8 ++-- .../Lru/LruInfoTests.cs | 4 +- .../Lru/LruItemMemoryLayoutDumps.cs | 2 +- .../Lru/LruItemSoakTests.cs | 22 +++++----- .../Lru/LruPolicyTests.cs | 6 +-- .../Lru/NoTelemetryPolicyTests.cs | 4 +- .../Lru/StopwatchTickConverterTests.cs | 2 +- .../Lru/TelemetryPolicyTests.cs | 10 ++--- .../Lru/TlruDateTimePolicyTests.cs | 10 ++--- .../Lru/TlruStopwatchPolicyTests.cs | 12 ++--- .../Lru/TlruTicksPolicyTests.cs | 10 ++--- .../Retry/RetryFact.cs | 4 +- .../Scheduler/BackgroundSchedulerTests.cs | 2 +- .../ScopedAsyncCacheTestBase.cs | 2 +- .../ScopedAsyncCacheTests.cs | 4 +- .../ScopedCacheSoakTests.cs | 3 +- .../ScopedCacheTestBase.cs | 4 +- .../ScopedCacheTests.cs | 6 +-- .../ScopedSoakTests.cs | 3 +- BitFaster.Caching.UnitTests/ScopedTests.cs | 6 +-- .../SingletonCacheTests.cs | 8 ++-- .../TestExpiryCalculator.cs | 2 +- BitFaster.Caching.UnitTests/Threaded.cs | 2 +- BitFaster.Caching.UnitTests/Timed.cs | 2 +- BitFaster.Caching.UnitTests/TypePropsTests.cs | 4 +- .../Atomic/AtomicFactoryAsyncCache.cs | 4 +- .../Atomic/AtomicFactoryScopedAsyncCache.cs | 4 +- .../Atomic/AtomicFactoryScopedCache.cs | 8 ++-- BitFaster.Caching/Buffers/ArrayExtensions.cs | 2 +- .../Buffers/MpmcBoundedBuffer.cs | 2 +- .../Buffers/StripedMpscBuffer.cs | 2 +- BitFaster.Caching/CacheEventProxyBase.cs | 4 +- BitFaster.Caching/Counters/Striped64.cs | 4 +- BitFaster.Caching/Disposer.cs | 2 +- BitFaster.Caching/Duration.cs | 4 +- BitFaster.Caching/IAsyncCacheExt.cs | 2 +- BitFaster.Caching/ICacheEvents.cs | 2 +- BitFaster.Caching/ICacheExt.cs | 2 +- BitFaster.Caching/ICacheMetrics.cs | 2 +- .../Lfu/Builder/AsyncConcurrentLfuBuilder.cs | 2 +- .../Lfu/Builder/ScopedConcurrentLfuBuilder.cs | 2 +- BitFaster.Caching/Lfu/CmSketch.cs | 2 +- BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs | 2 +- BitFaster.Caching/Lfu/ConcurrentLfuCore.cs | 34 +++++++------- BitFaster.Caching/Lfu/ConcurrentTLfu.cs | 3 +- BitFaster.Caching/Lfu/LfuCapacityPartition.cs | 2 +- BitFaster.Caching/Lfu/LfuNode.cs | 34 +++++++------- BitFaster.Caching/Lfu/LfuNodeList.cs | 2 +- BitFaster.Caching/Lfu/TimerWheel.cs | 8 ++-- BitFaster.Caching/Lru/Builder/LruInfo.cs | 6 +-- .../Lru/Builder/ScopedConcurrentLruBuilder.cs | 2 +- .../Lru/ConcurrentLruBuilderExtensions.cs | 2 +- BitFaster.Caching/Lru/ConcurrentLruCore.cs | 12 ++--- BitFaster.Caching/Lru/ITelemetryPolicy.cs | 2 +- BitFaster.Caching/Lru/ItemDestination.cs | 2 +- BitFaster.Caching/Lru/LruItem.cs | 36 +++++++-------- BitFaster.Caching/Lru/Time.cs | 4 +- BitFaster.Caching/Optional.cs | 2 +- .../Scheduler/BackgroundThreadScheduler.cs | 2 +- BitFaster.Caching/ScopedAsyncCache.cs | 2 +- BitFaster.Caching/Throw.cs | 2 +- 118 files changed, 407 insertions(+), 384 deletions(-) diff --git a/BitFaster.Caching.Benchmarks/DataStructureBenchmarks.cs b/BitFaster.Caching.Benchmarks/DataStructureBenchmarks.cs index b8b0d0fd..6c0d4ba7 100644 --- a/BitFaster.Caching.Benchmarks/DataStructureBenchmarks.cs +++ b/BitFaster.Caching.Benchmarks/DataStructureBenchmarks.cs @@ -1,9 +1,9 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; namespace BitFaster.Caching.Benchmarks { diff --git a/BitFaster.Caching.Benchmarks/DisposerBench.cs b/BitFaster.Caching.Benchmarks/DisposerBench.cs index b17fd36d..ed2eaa4c 100644 --- a/BitFaster.Caching.Benchmarks/DisposerBench.cs +++ b/BitFaster.Caching.Benchmarks/DisposerBench.cs @@ -88,7 +88,7 @@ public static void Dispose(T value) } public static class Disposer2 - { + { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Dispose(T value) { diff --git a/BitFaster.Caching.Benchmarks/Lfu/CmSketchNoPin.cs b/BitFaster.Caching.Benchmarks/Lfu/CmSketchNoPin.cs index 419ce3c4..57d2ba13 100644 --- a/BitFaster.Caching.Benchmarks/Lfu/CmSketchNoPin.cs +++ b/BitFaster.Caching.Benchmarks/Lfu/CmSketchNoPin.cs @@ -118,7 +118,7 @@ public void Clear() size = 0; } - // [MemberNotNull(nameof(table))] + // [MemberNotNull(nameof(table))] private void EnsureCapacity(long maximumSize) { int maximum = (int)Math.Min(maximumSize, int.MaxValue >> 1); diff --git a/BitFaster.Caching.Benchmarks/Lfu/LfuJustGetOrAdd.cs b/BitFaster.Caching.Benchmarks/Lfu/LfuJustGetOrAdd.cs index 5c3a4ce7..5b616d85 100644 --- a/BitFaster.Caching.Benchmarks/Lfu/LfuJustGetOrAdd.cs +++ b/BitFaster.Caching.Benchmarks/Lfu/LfuJustGetOrAdd.cs @@ -1,12 +1,12 @@ -using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using Benchly; +using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Jobs; using BitFaster.Caching.Lfu; using BitFaster.Caching.Scheduler; -using Benchly; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; namespace BitFaster.Caching.Benchmarks { @@ -40,7 +40,7 @@ public void GlobalSetup() [GlobalCleanup] public void GlobalCleanup() { - background.Dispose(); + background.Dispose(); } [Benchmark(Baseline = true)] diff --git a/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs b/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs index 970c2d9f..56ac003b 100644 --- a/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs +++ b/BitFaster.Caching.Benchmarks/Lfu/SketchFrequency.cs @@ -49,7 +49,7 @@ public int FrequencyFlat() { int count = 0; for (int i = 0; i < iterations; i++) - count += flatStd.EstimateFrequency(i) > flatStd.EstimateFrequency(i + 1) ? 1: 0; + count += flatStd.EstimateFrequency(i) > flatStd.EstimateFrequency(i + 1) ? 1 : 0; return count; } diff --git a/BitFaster.Caching.Benchmarks/Lru/LruCycleBench.cs b/BitFaster.Caching.Benchmarks/Lru/LruCycleBench.cs index 6627ca2e..995848a8 100644 --- a/BitFaster.Caching.Benchmarks/Lru/LruCycleBench.cs +++ b/BitFaster.Caching.Benchmarks/Lru/LruCycleBench.cs @@ -26,7 +26,7 @@ namespace BitFaster.Caching.Benchmarks.Lru [DisassemblyDiagnoser(printSource: true, maxDepth: 5)] [SimpleJob(RuntimeMoniker.Net48)] #endif - [SimpleJob(RuntimeMoniker.Net60)] + [SimpleJob(RuntimeMoniker.Net60)] [MemoryDiagnoser(displayGenColumns: false)] [HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")] public class LruCycleBench @@ -52,7 +52,7 @@ private void OnItemRemoved(object sender, ItemRemovedEventArgs e) field = e.Key; } - [Benchmark(Baseline =true)] + [Benchmark(Baseline = true)] public void FastConcurrentLru() { Func func = x => x; diff --git a/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAdd.cs b/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAdd.cs index 20ea8975..5b80ab9b 100644 --- a/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAdd.cs +++ b/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAdd.cs @@ -1,4 +1,8 @@ -using Benchly; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using Benchly; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Jobs; @@ -6,10 +10,6 @@ using BitFaster.Caching.Lru; using BitFaster.Caching.Scheduler; using Microsoft.Extensions.Caching.Memory; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Runtime.CompilerServices; namespace BitFaster.Caching.Benchmarks { @@ -39,7 +39,7 @@ namespace BitFaster.Caching.Benchmarks // [HardwareCounters(HardwareCounter.LlcMisses, HardwareCounter.CacheMisses)] // Requires Admin https://adamsitnik.com/Hardware-Counters-Diagnoser/ // [ThreadingDiagnoser] // Requires .NET Core [HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")] - [ColumnChart(Title= "Lookup Latency ({JOB})", Output = OutputMode.PerJob, Colors = "darkslategray,royalblue,royalblue,royalblue,royalblue,royalblue,royalblue,royalblue,#ffbf00,limegreen,indianred,indianred")] + [ColumnChart(Title = "Lookup Latency ({JOB})", Output = OutputMode.PerJob, Colors = "darkslategray,royalblue,royalblue,royalblue,royalblue,royalblue,royalblue,royalblue,#ffbf00,limegreen,indianred,indianred")] public class LruJustGetOrAdd { private static readonly ConcurrentDictionary dictionary = new ConcurrentDictionary(8, 9, EqualityComparer.Default); @@ -60,7 +60,7 @@ public class LruJustGetOrAdd private static readonly int key = 1; private static System.Runtime.Caching.MemoryCache memoryCache = System.Runtime.Caching.MemoryCache.Default; - Microsoft.Extensions.Caching.Memory.MemoryCache exMemoryCache + Microsoft.Extensions.Caching.Memory.MemoryCache exMemoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptionsAccessor()); [GlobalSetup] @@ -73,7 +73,7 @@ public void GlobalSetup() [GlobalCleanup] public void GlobalCleanup() { - background.Dispose(); + background.Dispose(); } [Benchmark(Baseline = true)] diff --git a/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAddGuid.cs b/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAddGuid.cs index 78602e6c..118fe987 100644 --- a/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAddGuid.cs +++ b/BitFaster.Caching.Benchmarks/Lru/LruJustGetOrAddGuid.cs @@ -1,4 +1,8 @@ -using Benchly; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Threading; +using Benchly; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Jobs; @@ -6,10 +10,6 @@ using BitFaster.Caching.Lru; using BitFaster.Caching.Scheduler; using Microsoft.Extensions.Caching.Memory; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading; namespace BitFaster.Caching.Benchmarks { @@ -23,7 +23,7 @@ namespace BitFaster.Caching.Benchmarks // [HardwareCounters(HardwareCounter.LlcMisses, HardwareCounter.CacheMisses)] // Requires Admin https://adamsitnik.com/Hardware-Counters-Diagnoser/ // [ThreadingDiagnoser] // Requires .NET Core [HideColumns("Job", "Median", "RatioSD", "Alloc Ratio")] - [ColumnChart(Title= "Guid Lookup Latency ({JOB})", Output = OutputMode.PerJob, Colors = "darkslategray,royalblue,royalblue,#ffbf00,indianred,indianred")] + [ColumnChart(Title = "Guid Lookup Latency ({JOB})", Output = OutputMode.PerJob, Colors = "darkslategray,royalblue,royalblue,#ffbf00,indianred,indianred")] public class LruJustGetOrAddGuid { private static readonly ConcurrentDictionary dictionary = new ConcurrentDictionary(8, 9, EqualityComparer.Default); @@ -38,7 +38,7 @@ public class LruJustGetOrAddGuid private static readonly int key = 1; private static System.Runtime.Caching.MemoryCache memoryCache = System.Runtime.Caching.MemoryCache.Default; - Microsoft.Extensions.Caching.Memory.MemoryCache exMemoryCache + Microsoft.Extensions.Caching.Memory.MemoryCache exMemoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptionsAccessor()); private static readonly byte[] b = new byte[8]; @@ -53,7 +53,7 @@ public void GlobalSetup() [GlobalCleanup] public void GlobalCleanup() { - background.Dispose(); + background.Dispose(); } [Benchmark(Baseline = true)] diff --git a/BitFaster.Caching.Benchmarks/Lru/LruMultiGet.cs b/BitFaster.Caching.Benchmarks/Lru/LruMultiGet.cs index 3fcb9aaf..b5740219 100644 --- a/BitFaster.Caching.Benchmarks/Lru/LruMultiGet.cs +++ b/BitFaster.Caching.Benchmarks/Lru/LruMultiGet.cs @@ -1,10 +1,10 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Jobs; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Runtime.Caching; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; +using BitFaster.Caching.Lru; namespace BitFaster.Caching.Benchmarks.Lru { @@ -71,7 +71,7 @@ public void ConcurrentDictionary() Func func = x => x; for (int j = 0; j < 4; j++) - { + { for (int i = 0; i < 6; i++) { dictionary.GetOrAdd(i, func); diff --git a/BitFaster.Caching.Benchmarks/ValueFactoryBenchmarks.cs b/BitFaster.Caching.Benchmarks/ValueFactoryBenchmarks.cs index 88be8754..306180be 100644 --- a/BitFaster.Caching.Benchmarks/ValueFactoryBenchmarks.cs +++ b/BitFaster.Caching.Benchmarks/ValueFactoryBenchmarks.cs @@ -66,7 +66,7 @@ public int Delegate() [Benchmark()] public int ValueFactory() { - var valueFactory = new ValueFactoryArg((k, v) => k + v, 2); + var valueFactory = new ValueFactoryArg((k, v) => k + v, 2); return Invoke>(valueFactory, 1); } @@ -107,7 +107,7 @@ public int Delegate() [Benchmark()] public int ValueFactory() { - var valueFactory = new ValueFactoryArg, int>((k, v) => k , (0, 1, 2)); + var valueFactory = new ValueFactoryArg, int>((k, v) => k, (0, 1, 2)); return Invoke, int>>(valueFactory, 1); } diff --git a/BitFaster.Caching.HitRateAnalysis/Analysis.cs b/BitFaster.Caching.HitRateAnalysis/Analysis.cs index 959306b7..5b81a94b 100644 --- a/BitFaster.Caching.HitRateAnalysis/Analysis.cs +++ b/BitFaster.Caching.HitRateAnalysis/Analysis.cs @@ -48,7 +48,7 @@ public void TestKey(K key) public static void WriteToFile(string path, IEnumerable> results) { - using (var writer = new StreamWriter(path)) + using (var writer = new StreamWriter(path)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) { csv.WriteRecords(results); diff --git a/BitFaster.Caching.HitRateAnalysis/Arc/ArcDataFile.cs b/BitFaster.Caching.HitRateAnalysis/Arc/ArcDataFile.cs index 4afaae48..a22c4d81 100644 --- a/BitFaster.Caching.HitRateAnalysis/Arc/ArcDataFile.cs +++ b/BitFaster.Caching.HitRateAnalysis/Arc/ArcDataFile.cs @@ -70,28 +70,28 @@ public async Task DownloadIfNotExistsAsync() public IEnumerable EnumerateFileData() { - // File Format: - // Every line in every file has four fields. - // - // First field: starting_block - // Second field: number_of_blocks(each block is 512 bytes) - // - // Third field: ignore - // Fourth field: request_number(starts at 0) - // - // - // Example: first line in P6.lis is - // 110765 64 0 0 - // - // - // 110765 starting block - // - // 64 64 blocks each of 512 bytes - // so this represents 64 requests(each of a 512 byte page) from 110765 to 110828 - // - // 0 ignore - // - // 0 request number(goes from 0 to n-1) + // File Format: + // Every line in every file has four fields. + // + // First field: starting_block + // Second field: number_of_blocks(each block is 512 bytes) + // + // Third field: ignore + // Fourth field: request_number(starts at 0) + // + // + // Example: first line in P6.lis is + // 110765 64 0 0 + // + // + // 110765 starting block + // + // 64 64 blocks each of 512 bytes + // so this represents 64 requests(each of a 512 byte page) from 110765 to 110828 + // + // 0 ignore + // + // 0 request number(goes from 0 to n-1) using StreamReader sr = new StreamReader(FilePath); diff --git a/BitFaster.Caching.HitRateAnalysis/Arc/Runner.cs b/BitFaster.Caching.HitRateAnalysis/Arc/Runner.cs index 8ec2dc64..a681c7c9 100644 --- a/BitFaster.Caching.HitRateAnalysis/Arc/Runner.cs +++ b/BitFaster.Caching.HitRateAnalysis/Arc/Runner.cs @@ -22,7 +22,7 @@ public async Task Run() await this.config.File.DownloadIfNotExistsAsync(); Console.WriteLine("Running..."); - + var sw = Stopwatch.StartNew(); int count = this.config.Analysis.First().CacheSize >= 1_000_000 ? AnalyzeLarge() : AnalyzeSmall(); diff --git a/BitFaster.Caching.HitRateAnalysis/Glimpse/DataFile.cs b/BitFaster.Caching.HitRateAnalysis/Glimpse/DataFile.cs index 6d5b3273..d5353afa 100644 --- a/BitFaster.Caching.HitRateAnalysis/Glimpse/DataFile.cs +++ b/BitFaster.Caching.HitRateAnalysis/Glimpse/DataFile.cs @@ -60,7 +60,7 @@ public static IEnumerable EnumerateFileData() var line = sr.ReadLine(); if (long.TryParse(line, out var value)) - { + { yield return value; } } diff --git a/BitFaster.Caching.HitRateAnalysis/PlotExt.cs b/BitFaster.Caching.HitRateAnalysis/PlotExt.cs index cfa13e19..25419351 100644 --- a/BitFaster.Caching.HitRateAnalysis/PlotExt.cs +++ b/BitFaster.Caching.HitRateAnalysis/PlotExt.cs @@ -31,7 +31,7 @@ public static GenericChart WithLayout(this GenericChart chart, string title) { var font = new FSharpOption(Font.init(Size: new FSharpOption(24))); FSharpOption t = Title.init(Text: title, X: 0.5, Font: font); - FSharpOption <Color> plotBGColor = new FSharpOption<Color>(Color.fromKeyword(ColorKeyword.WhiteSmoke)); + FSharpOption<Color> plotBGColor = new FSharpOption<Color>(Color.fromKeyword(ColorKeyword.WhiteSmoke)); Layout layout = Layout.init<IConvertible>(PaperBGColor: plotBGColor, PlotBGColor: plotBGColor, Title: t); return chart.WithLayout(layout); } diff --git a/BitFaster.Caching.HitRateAnalysis/Wikibench/WikiBenchFile.cs b/BitFaster.Caching.HitRateAnalysis/Wikibench/WikiBenchFile.cs index 937a5fcd..ed45ef9b 100644 --- a/BitFaster.Caching.HitRateAnalysis/Wikibench/WikiBenchFile.cs +++ b/BitFaster.Caching.HitRateAnalysis/Wikibench/WikiBenchFile.cs @@ -67,16 +67,16 @@ public IEnumerable<Uri> EnumerateUris() if (parsed != null) { if (Uri.TryCreate(parsed, UriKind.Relative, out var result)) - { - yield return result; + { + yield return result; } } } } } - private static readonly string[] containsFilters = - { + private static readonly string[] containsFilters = + { "?search = ", "User+talk", "User_talk", @@ -93,12 +93,12 @@ public IEnumerable<Uri> EnumerateUris() private static readonly string[] startswithFilters = { - "/wiki/Special:Search", - "/w/query.php", - "/wiki/Talk:", + "/wiki/Special:Search", + "/w/query.php", + "/wiki/Talk:", "/wiki/Special:AutoLogin", - "/Special:UserLogin", - "/w/api.php", + "/Special:UserLogin", + "/w/api.php", "/error:" }; @@ -113,7 +113,7 @@ private static string ParseLine(string line) return null; } - int start = line.IndexOf('/', 25+7); + int start = line.IndexOf('/', 25 + 7); if (start == -1) { diff --git a/BitFaster.Caching.ThroughputAnalysis/CacheFactory.cs b/BitFaster.Caching.ThroughputAnalysis/CacheFactory.cs index b4212c87..a7c4bf1b 100644 --- a/BitFaster.Caching.ThroughputAnalysis/CacheFactory.cs +++ b/BitFaster.Caching.ThroughputAnalysis/CacheFactory.cs @@ -97,9 +97,9 @@ public ConcurrentLfuFactory(int capacity) { var scheduler = new BackgroundThreadScheduler(); var cache = new ConcurrentLfu<long, int>( - concurrencyLevel: threadCount, - capacity: capacity, - scheduler: scheduler, + concurrencyLevel: threadCount, + capacity: capacity, + scheduler: scheduler, EqualityComparer<long>.Default); return (scheduler, cache); diff --git a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs index ea36663d..debaee50 100644 --- a/BitFaster.Caching.ThroughputAnalysis/Exporter.cs +++ b/BitFaster.Caching.ThroughputAnalysis/Exporter.cs @@ -26,7 +26,7 @@ public Exporter(int minThreads, int maxThreads) resultTable.Clear(); resultTable.Columns.Add("ThreadCount"); - foreach (var tc in Enumerable.Range(minThreads, maxThreads - (minThreads-1)).ToArray()) + foreach (var tc in Enumerable.Range(minThreads, maxThreads - (minThreads - 1)).ToArray()) { resultTable.Columns.Add(tc.ToString()); } @@ -75,7 +75,7 @@ public void ExportPlot(Mode mode, int cacheSize) { var columns = new List<int>(); - for(int i = 1; i < resultTable.Columns.Count; i++) + for (int i = 1; i < resultTable.Columns.Count; i++) { columns.Add(int.Parse(resultTable.Columns[i].ColumnName)); } @@ -92,7 +92,7 @@ public void ExportPlot(Mode mode, int cacheSize) rowData.Add(double.Parse(row[i].ToString()) * 1_000_000); } - // var chart = Chart.Line<int, double, string>(columns, rowData, Name: name, MarkerColor: MapColor(name)); + // var chart = Chart.Line<int, double, string>(columns, rowData, Name: name, MarkerColor: MapColor(name)); var chart = Chart2D.Chart.Line<int, double, string>(columns, rowData, Name: name, MarkerColor: MapColor(name)); charts.Add(chart); diff --git a/BitFaster.Caching.ThroughputAnalysis/ParallelBenchmark.cs b/BitFaster.Caching.ThroughputAnalysis/ParallelBenchmark.cs index 673a6004..f30ed693 100644 --- a/BitFaster.Caching.ThroughputAnalysis/ParallelBenchmark.cs +++ b/BitFaster.Caching.ThroughputAnalysis/ParallelBenchmark.cs @@ -26,8 +26,8 @@ public static TimeSpan Run(Action<int> action, int threadCount) // try to mitigate spam from MemoryCache for (int i = 0; i < 3; i++) - { - GC.Collect(); + { + GC.Collect(); } var sw = Stopwatch.StartNew(); diff --git a/BitFaster.Caching.ThroughputAnalysis/Runner.cs b/BitFaster.Caching.ThroughputAnalysis/Runner.cs index f6caa276..0877987b 100644 --- a/BitFaster.Caching.ThroughputAnalysis/Runner.cs +++ b/BitFaster.Caching.ThroughputAnalysis/Runner.cs @@ -21,7 +21,7 @@ public static void Run(Mode mode, int cacheSize) { RunTest(value, cacheSize); } - } + } } private static void RunTest(Mode mode, int cacheSize) @@ -48,7 +48,7 @@ private static void RunTest(Mode mode, int cacheSize) Console.WriteLine($"Running {mode} with size {capacity} over {maxThreads} threads..."); Console.WriteLine(); - foreach (int tc in Enumerable.Range(minThreads, maxThreads - (minThreads -1)).ToArray()) + foreach (int tc in Enumerable.Range(minThreads, maxThreads - (minThreads - 1)).ToArray()) { const int warmup = 3; const int runs = 11; diff --git a/BitFaster.Caching.ThroughputAnalysis/ThreadPoolInspector.cs b/BitFaster.Caching.ThroughputAnalysis/ThreadPoolInspector.cs index 55426409..3a5c0603 100644 --- a/BitFaster.Caching.ThroughputAnalysis/ThreadPoolInspector.cs +++ b/BitFaster.Caching.ThroughputAnalysis/ThreadPoolInspector.cs @@ -8,7 +8,7 @@ internal class ThreadPoolInspector public static void WaitForEmpty() { int count = 0; - while (ThreadPool.PendingWorkItemCount > 0) + while (ThreadPool.PendingWorkItemCount > 0) { Thread.Yield(); Thread.Sleep(1); diff --git a/BitFaster.Caching.ThroughputAnalysis/ThroughputBenchmark.cs b/BitFaster.Caching.ThroughputAnalysis/ThroughputBenchmark.cs index 8f6b30b0..45ec177b 100644 --- a/BitFaster.Caching.ThroughputAnalysis/ThroughputBenchmark.cs +++ b/BitFaster.Caching.ThroughputAnalysis/ThroughputBenchmark.cs @@ -46,7 +46,7 @@ public abstract class ThroughputBenchmarkBase var sw = Stopwatch.StartNew(); Run(Stage.Pilot, 0, threads, config, cache); - valid = sw.Elapsed > TimeSpan.FromMilliseconds(800) ? valid + 1 : 0; + valid = sw.Elapsed > TimeSpan.FromMilliseconds(800) ? valid + 1 : 0; if (valid > 3) { @@ -54,8 +54,8 @@ public abstract class ThroughputBenchmarkBase } if (valid == 0) - { - config.Iterations = config.Iterations < 5 ? config.Iterations + 1 : (int)(1.2 * config.Iterations); + { + config.Iterations = config.Iterations < 5 ? config.Iterations + 1 : (int)(1.2 * config.Iterations); } } diff --git a/BitFaster.Caching.UnitTests.Std/DurationTests.cs b/BitFaster.Caching.UnitTests.Std/DurationTests.cs index 7a58df9f..6155a74e 100644 --- a/BitFaster.Caching.UnitTests.Std/DurationTests.cs +++ b/BitFaster.Caching.UnitTests.Std/DurationTests.cs @@ -47,7 +47,7 @@ public void ToTimeSpan() { // for Stopwatch.GetTimestamp() this is number of ticks new Duration(1 * Stopwatch.Frequency).ToTimeSpan().Should().BeCloseTo(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(10)); - } + } } [Fact] @@ -63,7 +63,7 @@ public void FromTimeSpan() { Duration.FromTimeSpan(TimeSpan.FromSeconds(1)).raw .Should().Be(Stopwatch.Frequency); - } + } } // This is for diagnostic purposes when tests run on different operating systems. diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs index 00ff2a1c..96c03053 100644 --- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs +++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryAsyncCacheTests.cs @@ -4,11 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using BitFaster.Caching.Lru; using BitFaster.Caching.Atomic; +using BitFaster.Caching.Lru; using FluentAssertions; -using Xunit; using Moq; +using Xunit; namespace BitFaster.Caching.UnitTests.Atomic { @@ -258,7 +258,7 @@ public async Task WhenFactoryThrowsEmptyKeyIsNotEnumerable() cache.Keys.Count().Should().Be(0); } - // backcompat: remove conditional compile + // backcompat: remove conditional compile #if NET [Fact] public void WhenRemovedValueIsReturned() diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs index 0c8bd66c..2ef02148 100644 --- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs +++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheTests.cs @@ -2,11 +2,11 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using BitFaster.Caching.Lru; using BitFaster.Caching.Atomic; +using BitFaster.Caching.Lru; using FluentAssertions; -using Xunit; using Moq; +using Xunit; namespace BitFaster.Caching.UnitTests.Atomic { diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs index e9244c6c..80f511f8 100644 --- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs +++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedAsyncCacheTests.cs @@ -3,11 +3,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using BitFaster.Caching.Lru; using BitFaster.Caching.Atomic; +using BitFaster.Caching.Lru; using FluentAssertions; -using Xunit; using Moq; +using Xunit; namespace BitFaster.Caching.UnitTests.Atomic { diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs index 58254424..4e70b94a 100644 --- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs +++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryScopedCacheTests.cs @@ -3,11 +3,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using BitFaster.Caching.Lru; using BitFaster.Caching.Atomic; +using BitFaster.Caching.Lru; using FluentAssertions; -using Xunit; using Moq; +using Xunit; namespace BitFaster.Caching.UnitTests.Atomic { diff --git a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs index dfe9a32c..ee7d2de5 100644 --- a/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs +++ b/BitFaster.Caching.UnitTests/Atomic/AtomicFactoryTests.cs @@ -176,7 +176,7 @@ public async Task WhenCallersRunConcurrentlyAndFailExceptionIsPropogated() // Therefore, try many times and verify it was possible to provoke // at least once. while (count++ < 256) - { + { var enter1 = new ManualResetEvent(false); var enter2 = new ManualResetEvent(false); var factory = new ManualResetEvent(false); diff --git a/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs b/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs index 02473a91..7160a28b 100644 --- a/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs +++ b/BitFaster.Caching.UnitTests/Atomic/ConcurrentDictionaryExtensionTests.cs @@ -34,7 +34,7 @@ public async Task WhenItemIsAddedAsyncItCanBeRetrieved() [Fact] public void WhenItemIsAddedWithArgItCanBeRetrieved() { - dictionary.GetOrAdd(1, (k,a) => k + a, 2); + dictionary.GetOrAdd(1, (k, a) => k + a, 2); dictionary.TryGetValue(1, out int value).Should().BeTrue(); value.Should().Be(3); diff --git a/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs b/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs index 01fab64f..4a119269 100644 --- a/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Buffers/MpmcBoundedBufferSoakTests.cs @@ -26,7 +26,7 @@ public MpmcBoundedBufferSoakTests(ITestOutputHelper testOutputHelper) public async Task WhenAddIsContendedBufferCanBeFilled(int iteration) { this.testOutputHelper.WriteLine($"Iteration {iteration}"); - + await Threaded.Run(4, () => { while (buffer.TryAdd("hello") != BufferStatus.Full) diff --git a/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs b/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs index edc77a36..3eec77f3 100644 --- a/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Buffers/MpscBoundedBufferSoakTests.cs @@ -90,7 +90,7 @@ public async Task WhileBufferIsFilledCountCanBeTaken() { this.testOutputHelper.WriteLine($"ProcessorCount={Environment.ProcessorCount}."); - var fill = CreateParallelFill(buffer, threads:4, itemsPerThread:256); + var fill = CreateParallelFill(buffer, threads: 4, itemsPerThread: 256); var count = Threaded.Run(4, () => { @@ -103,13 +103,13 @@ public async Task WhileBufferIsFilledCountCanBeTaken() count = newcount; } }); - + await fill.TimeoutAfter(Timeout, "fill timed out"); await count.TimeoutAfter(Timeout, "count timed out"); } private Task CreateParallelFill(MpscBoundedBuffer<string> buffer, int threads, int itemsPerThread) - { + { return Threaded.Run(threads, () => { var spin = new SpinWait(); diff --git a/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs b/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs index 0c621f0d..df4b7a4a 100644 --- a/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs +++ b/BitFaster.Caching.UnitTests/Buffers/StripedMpscBufferTests.cs @@ -99,8 +99,8 @@ public void WhenDrainBufferIsSmallerThanStripedBufferDrainReturnsBufferItemCount } } - var array = new string[bufferSize+4]; - buffer.DrainTo(array).Should().Be(bufferSize+4); + var array = new string[bufferSize + 4]; + buffer.DrainTo(array).Should().Be(bufferSize + 4); } [Fact] diff --git a/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs b/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs index 6cbd4908..891631be 100644 --- a/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs +++ b/BitFaster.Caching.UnitTests/CacheEventProxyBaseTests.cs @@ -54,7 +54,7 @@ public void WhenTwoRemovedEventHandlersAddedThenOneRemovedEventIsFired() this.removedItems.First().Key.Should().Be(1); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WheUpdatedEventHandlerIsRegisteredItIsFired() diff --git a/BitFaster.Caching.UnitTests/CacheTests.cs b/BitFaster.Caching.UnitTests/CacheTests.cs index 5cdeafa0..5a1f04e6 100644 --- a/BitFaster.Caching.UnitTests/CacheTests.cs +++ b/BitFaster.Caching.UnitTests/CacheTests.cs @@ -11,7 +11,7 @@ namespace BitFaster.Caching.UnitTests // Tests for interface default implementations. public class CacheTests { -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenCacheInterfaceDefaultGetOrAddFallback() diff --git a/BitFaster.Caching.UnitTests/Disposable.cs b/BitFaster.Caching.UnitTests/Disposable.cs index 2ca08414..2ba4f183 100644 --- a/BitFaster.Caching.UnitTests/Disposable.cs +++ b/BitFaster.Caching.UnitTests/Disposable.cs @@ -6,7 +6,7 @@ namespace BitFaster.Caching.UnitTests public class Disposable : IDisposable { public Disposable() { } - + public Disposable(int state) { this.State = state; } public bool IsDisposed { get; set; } diff --git a/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs b/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs index 4c64737e..bbdbafba 100644 --- a/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs +++ b/BitFaster.Caching.UnitTests/ExpireAfterAccessTests.cs @@ -9,7 +9,7 @@ public class ExpireAfterAccessTests private readonly Duration expiry = Duration.FromMinutes(1); private readonly ExpireAfterAccess<int, int> expiryCalculator; - public ExpireAfterAccessTests() + public ExpireAfterAccessTests() { expiryCalculator = new(expiry.ToTimeSpan()); } @@ -22,7 +22,7 @@ public void TimeToExpireReturnsCtorArg() [Fact] public void AfterCreateReturnsTimeToExpire() - { + { expiryCalculator.GetExpireAfterCreate(1, 2).Should().Be(expiry); } diff --git a/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs b/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs index 57774eed..de9dd0c4 100644 --- a/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs +++ b/BitFaster.Caching.UnitTests/ExpireAfterWriteTests.cs @@ -16,7 +16,7 @@ public ExpireAfterWriteTests() [Fact] public void TimeToExpireReturnsCtorArg() - { + { expiryCalculator.TimeToExpire.Should().Be(expiry.ToTimeSpan()); } diff --git a/BitFaster.Caching.UnitTests/Intrinsics.cs b/BitFaster.Caching.UnitTests/Intrinsics.cs index 139cb350..69764cf0 100644 --- a/BitFaster.Caching.UnitTests/Intrinsics.cs +++ b/BitFaster.Caching.UnitTests/Intrinsics.cs @@ -14,13 +14,13 @@ public static class Intrinsics public static void SkipAvxIfNotSupported<I>() { #if NET - #if NET6_0_OR_GREATER +#if NET6_0_OR_GREATER // when we are trying to test Avx2/Arm64, skip the test if it's not supported Skip.If(typeof(I) == typeof(DetectIsa) && !(Avx2.IsSupported || AdvSimd.Arm64.IsSupported)); - #else +#else // when we are trying to test Avx2, skip the test if it's not supported Skip.If(typeof(I) == typeof(DetectIsa) && !Avx2.IsSupported); - #endif +#endif #else Skip.If(true); diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs index f3318658..87a98db9 100644 --- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuCoreTests.cs @@ -18,7 +18,7 @@ public abstract class ConcurrentLfuCoreTests private ICache<int, int> lfu; - public abstract ICache<K, V> Create<K,V>(); + public abstract ICache<K, V> Create<K, V>(); public abstract void DoMaintenance<K, V>(ICache<K, V> cache); public ConcurrentLfuCoreTests() @@ -133,7 +133,7 @@ public void WhenItemDoesntMatchTryRemoveDoesNotRemove() lfu.TryGet(1, out var value).Should().BeTrue(); } #endif - + [Fact] public void WhenClearedCacheIsEmpty() { @@ -189,7 +189,7 @@ public void WhenItemsAddedEnumerateContainsKvps() public class ConcurrentTLfuWrapperTests : ConcurrentLfuCoreTests { - public override ICache<K, V> Create<K,V>() + public override ICache<K, V> Create<K, V>() { return new ConcurrentTLfu<K, V>(capacity, new ExpireAfterWrite<K, V>(timeToLive)); } diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs index 9c9f29f9..f2165c2e 100644 --- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs @@ -153,7 +153,8 @@ public async Task WhenConcurrentGetCacheEndsInConsistentState(int iteration) { var lfu = CreateWithBackgroundScheduler(); - await Threaded.Run(threads, () => { + await Threaded.Run(threads, () => + { for (int i = 0; i < loopIterations; i++) { lfu.GetOrAdd(i + 1, i => i.ToString()); @@ -169,7 +170,8 @@ public async Task WhenConcurrentGetAsyncCacheEndsInConsistentState(int iteration { var lfu = CreateWithBackgroundScheduler(); - await Threaded.RunAsync(threads, async () => { + await Threaded.RunAsync(threads, async () => + { for (int i = 0; i < loopIterations; i++) { await lfu.GetOrAddAsync(i + 1, i => Task.FromResult(i.ToString())); @@ -185,7 +187,8 @@ public async Task WhenConcurrentGetWithArgCacheEndsInConsistentState(int iterati { var lfu = CreateWithBackgroundScheduler(); - await Threaded.Run(threads, () => { + await Threaded.Run(threads, () => + { for (int i = 0; i < loopIterations; i++) { // use the arg overload @@ -202,7 +205,8 @@ public async Task WhenConcurrentGetAsyncWithArgCacheEndsInConsistentState(int it { var lfu = CreateWithBackgroundScheduler(); - await Threaded.RunAsync(threads, async () => { + await Threaded.RunAsync(threads, async () => + { for (int i = 0; i < loopIterations; i++) { // use the arg overload @@ -219,7 +223,8 @@ public async Task WhenConcurrentGetAndUpdateCacheEndsInConsistentState(int itera { var lfu = CreateWithBackgroundScheduler(); - await Threaded.Run(threads, () => { + await Threaded.Run(threads, () => + { for (int i = 0; i < loopIterations; i++) { lfu.TryUpdate(i + 1, i.ToString()); @@ -236,7 +241,8 @@ public async Task WhenSoakConcurrentGetAndRemoveCacheEndsInConsistentState(int i { var lfu = CreateWithBackgroundScheduler(); - await Threaded.Run(threads, () => { + await Threaded.Run(threads, () => + { for (int i = 0; i < loopIterations; i++) { lfu.TryRemove(i + 1); @@ -253,7 +259,8 @@ public async Task WhenConcurrentGetAndRemoveKvpCacheEndsInConsistentState(int it { var lfu = CreateWithBackgroundScheduler(); - await Threaded.Run(threads, () => { + await Threaded.Run(threads, () => + { for (int i = 0; i < loopIterations; i++) { lfu.TryRemove(new KeyValuePair<int, string>(i + 1, (i + 1).ToString())); @@ -295,7 +302,7 @@ await Threaded.Run(threads, i => public async Task WhenConcurrentUpdateAndRemoveKvp() { var cache = new ConcurrentLfu<int, string>(1, 20, new BackgroundThreadScheduler(), EqualityComparer<int>.Default); - TaskCompletionSource<int> tcs = new TaskCompletionSource<int> (); + TaskCompletionSource<int> tcs = new TaskCompletionSource<int>(); var removal = Task.Run(() => { @@ -323,7 +330,7 @@ public async Task WhenConcurrentUpdateAndRemoveKvp() [Theory] [Repeat(10)] public async Task WhenValueIsBigStructNoLiveLock(int _) - { + { using var source = new CancellationTokenSource(); var started = new TaskCompletionSource<bool>(); var cache = new ConcurrentLfu<int, Guid>(1, 20, new BackgroundThreadScheduler(), EqualityComparer<int>.Default); @@ -345,13 +352,13 @@ private void Setter(ICache<int, Guid> cache, CancellationToken cancelToken, Task cache.AddOrUpdate(1, Guid.NewGuid()); if (cancelToken.IsCancellationRequested) - { - return; + { + return; } } } - private void Checker(ICache<int, Guid> cache,CancellationTokenSource source) + private void Checker(ICache<int, Guid> cache, CancellationTokenSource source) { for (int count = 0; count < 100_000; ++count) { @@ -378,7 +385,7 @@ private async Task RunIntegrityCheckAsync(ConcurrentLfu<int, string> lfu, int it RunIntegrityCheck(lfu, this.output); } - private static void RunIntegrityCheck<K,V>(ConcurrentLfu<K,V> cache, ITestOutputHelper output) + private static void RunIntegrityCheck<K, V>(ConcurrentLfu<K, V> cache, ITestOutputHelper output) { new ConcurrentLfuIntegrityChecker<K, V, AccessOrderNode<K, V>, AccessOrderPolicy<K, V>>(cache.Core).Validate(output); } @@ -442,7 +449,7 @@ private void VerifyLruInDictionary(LfuNodeList<K, V> lfuNodes, ITestOutputHelper { var node = lfuNodes.First; - while (node != null) + while (node != null) { node.WasRemoved.Should().BeFalse(); node.WasDeleted.Should().BeFalse(); diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs index 0f3756bc..a301a1bb 100644 --- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuTests.cs @@ -368,9 +368,9 @@ public void WhenHitRateChangesWindowSizeIsAdapted() // W [19] Protected [12,13,14,15,16,17,18,0,1,2,3,4,5,6,7] Probation [8,9,10,11] for (int j = 0; j < 10; j++) for (int i = 0; i < 20; i++) - { - cache.GetOrAdd(i, k => k); - } + { + cache.GetOrAdd(i, k => k); + } cache.DoMaintenance(); LogLru(); @@ -476,7 +476,7 @@ public void WhenWriteBufferIsFullAddDoesMaintenance() cache.TryGet(-1, out var _).Should().BeFalse(); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenWriteBufferIsFullUpdatesAreDropped() @@ -602,7 +602,7 @@ public void WhenItemIsUpdatedItIsUpdated() [Fact] public void WhenKeyExistsAddOrUpdateGuidUpdatesExistingItem() - { + { var lfu2 = new ConcurrentLfu<int, Guid>(1, 40, new BackgroundThreadScheduler(), EqualityComparer<int>.Default); var b = new byte[8]; @@ -797,7 +797,7 @@ public void TrimWhileItemsInWriteBufferRemovesNItems() this.output.WriteLine($"Count {cache.Count}"); this.output.WriteLine($"Keys {string.Join(",", cache.Keys.Select(k => k.ToString()))}"); - + } private void LogLru() diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs index 1fa61d3b..4ad9a575 100644 --- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuSoakTests.cs @@ -29,7 +29,8 @@ public async Task GetOrAddWithExpiry(int iteration) { var lfu = new ConcurrentTLfu<int, string>(20, new ExpireAfterWrite<int, string>(TimeSpan.FromMilliseconds(10))); - await Threaded.RunAsync(threads, async () => { + await Threaded.RunAsync(threads, async () => + { for (int i = 0; i < loopIterations; i++) { await lfu.GetOrAddAsync(i + 1, i => Task.FromResult(i.ToString())); diff --git a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs index 59b0ad3f..328e5e02 100644 --- a/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/ConcurrentTLfuTests.cs @@ -29,7 +29,7 @@ public ConcurrentTLfuTests() // This is a scenario test to verify maintenance is run promptly after read. [RetryFact] public void WhenItemIsAccessedTimeToExpireIsUpdated() - { + { var cache = new ConcurrentLfuBuilder<int, int>() .WithCapacity(10) .WithExpireAfterAccess(TimeSpan.FromSeconds(5)) @@ -49,7 +49,7 @@ public void WhenItemIsAccessedTimeToExpireIsUpdated() }, TimeSpan.FromSeconds(2), cache => - { + { cache.TryGet(1, out var value).Should().BeTrue(); cache.TryGet(1, out value).Should().BeTrue(); } @@ -89,7 +89,7 @@ public void DefaultSchedulerIsThreadPool() [Fact] public void WhenCalculatorIsAfterWritePolicyIsAfterWrite() - { + { lfu.Policy.ExpireAfterWrite.HasValue.Should().BeTrue(); lfu.Policy.ExpireAfterWrite.Value.TimeToLive.Should().Be(timeToLive); } diff --git a/BitFaster.Caching.UnitTests/Lfu/LfuNodeSoakTest.cs b/BitFaster.Caching.UnitTests/Lfu/LfuNodeSoakTest.cs index 9fa69f1d..6e231d01 100644 --- a/BitFaster.Caching.UnitTests/Lfu/LfuNodeSoakTest.cs +++ b/BitFaster.Caching.UnitTests/Lfu/LfuNodeSoakTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; using System.Threading.Tasks; using BitFaster.Caching.Lfu; @@ -18,7 +18,7 @@ public class LfuNodeSoakTest [Theory] [Repeat(soakIterations)] public async Task DetectTornStruct(int _) - { + { using var source = new CancellationTokenSource(); var started = new TaskCompletionSource<bool>(); @@ -39,8 +39,8 @@ private void Setter(CancellationToken cancelToken, TaskCompletionSource<bool> st item.SeqLockWrite(MassiveStruct.B); if (cancelToken.IsCancellationRequested) - { - return; + { + return; } } } @@ -54,8 +54,8 @@ private void Checker(CancellationTokenSource source) var t = item.SeqLockRead(); if (t != MassiveStruct.A && t != MassiveStruct.B) - { - throw new Exception($"Value is torn after {count} iterations"); + { + throw new Exception($"Value is torn after {count} iterations"); } } diff --git a/BitFaster.Caching.UnitTests/Lfu/NodeMemoryLayoutDumps.cs b/BitFaster.Caching.UnitTests/Lfu/NodeMemoryLayoutDumps.cs index f0b6cd04..159fe1f7 100644 --- a/BitFaster.Caching.UnitTests/Lfu/NodeMemoryLayoutDumps.cs +++ b/BitFaster.Caching.UnitTests/Lfu/NodeMemoryLayoutDumps.cs @@ -44,7 +44,7 @@ public NodeMemoryLayoutDumps(ITestOutputHelper testOutputHelper) //|=====================================================| [Fact] public void DumpAccessOrderNode() - { + { var layout = TypeLayout.GetLayout<AccessOrderNode<object, object>>(includePaddings: true); testOutputHelper.WriteLine(layout.ToString()); } diff --git a/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs b/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs index 25bac835..3300deac 100644 --- a/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs +++ b/BitFaster.Caching.UnitTests/Lfu/TimerWheelTests.cs @@ -308,7 +308,7 @@ private static IEnumerable<object[]> CreateSchedule() return schedule; } } - + public class DisposeTracker : IDisposable { public bool Expired { get; set; } diff --git a/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs index e311f6d7..cdf0cc59 100644 --- a/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/AfterAccessPolicyTests.cs @@ -1,7 +1,7 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Threading.Tasks; +using BitFaster.Caching.Lru; +using FluentAssertions; using Xunit; namespace BitFaster.Caching.UnitTests.Lru diff --git a/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs b/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs index 4c5ede93..b2a6f443 100644 --- a/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/CacheExtTests.cs @@ -26,7 +26,7 @@ public void CanUseICache2FromConcurrentLfuBuilder() var cache = new ConcurrentLfuBuilder<int, string>() .WithCapacity(5) .Build(); - + var cache2 = (ICacheExt<int, string>)cache; cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).Should().Be("43"); cache2.TryRemove(43, out _).Should().BeFalse(); @@ -41,7 +41,7 @@ public void CanUseICache2FromConcurrentLruBuilder() .WithCapacity(5) .WithExpireAfterAccess(TimeSpan.FromSeconds(5)) .Build(); - + var cache2 = (ICacheExt<int, string>)cache; cache2.GetOrAdd(42, static (k, i) => (k + i).ToString(), 1).Should().Be("43"); cache2.TryRemove(43, out _).Should().BeFalse(); diff --git a/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs b/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs index 4b0b790f..f2fc32d9 100644 --- a/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/ClassicLruTests.cs @@ -1,12 +1,12 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BitFaster.Caching.Lru; +using FluentAssertions; using Xunit; -using System.Collections; namespace BitFaster.Caching.UnitTests.Lru { @@ -428,7 +428,7 @@ public void WhenKeyDoesNotExistTryUpdateReturnsFalse() lru.TryUpdate(2, "3").Should().BeFalse(); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenKeyExistsTryUpdateIncrementsUpdateCount() @@ -537,7 +537,7 @@ public void WhenItemsAreDisposableClearDisposesItemsOnRemove() [Fact] public void WhenTrimCountIsZeroThrows() - { + { lru.Invoking(l => lru.Trim(0)).Should().Throw<ArgumentOutOfRangeException>(); } diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs index fbdb8a05..47fe23fd 100644 --- a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruAfterAccessTests.cs @@ -111,7 +111,7 @@ public void WhenItemIsReadTtlIsExtended() lru, lru => { - + lru.GetOrAdd(1, valueFactory.Create); @@ -121,7 +121,7 @@ public void WhenItemIsReadTtlIsExtended() lru => { lru.TryGet(1, out _).Should().BeTrue($"First"); - }, + }, TimeSpan.FromMilliseconds(75), lru => { @@ -186,7 +186,7 @@ public void WhenItemsAreExpiredExpireRemovesExpiredItems() return lru; }, timeToLive.MultiplyBy(ttlWaitMlutiplier), - lru => + lru => { lru.Policy.ExpireAfterAccess.Value.TrimExpired(); diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs index fe94c0b9..aa276947 100644 --- a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruBuilderTests.cs @@ -1,6 +1,6 @@ using System; -using BitFaster.Caching.Lru; using BitFaster.Caching.Atomic; +using BitFaster.Caching.Lru; using FluentAssertions; using Xunit; @@ -255,7 +255,7 @@ public void TestExpireAfterAccessAndWriteAndExpireAfterThrows() [Fact] public void TestScopedWithExpireAfterThrows() { - var builder = new ConcurrentLruBuilder<string, Disposable>() + var builder = new ConcurrentLruBuilder<string, Disposable>() .WithExpireAfter(new TestExpiryCalculator<string, Disposable>((k, v) => Duration.FromMinutes(5))) .AsScopedCache(); @@ -436,7 +436,7 @@ public void WithScopedAsAsync() { IScopedAsyncCache<int, Disposable> lru = new ConcurrentLruBuilder<int, Disposable>() .AsScopedCache() - .AsAsyncCache() + .AsAsyncCache() .WithCapacity(3) .Build(); diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruSoakTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruSoakTests.cs index def2f841..f3755587 100644 --- a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruSoakTests.cs @@ -32,7 +32,8 @@ public async Task WhenSoakConcurrentGetCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int i = 0; i < 100000; i++) { lru.GetOrAdd(i + 1, i => i.ToString()); @@ -53,7 +54,8 @@ public async Task WhenSoakConcurrentGetAsyncCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.RunAsync(4, async () => { + await Threaded.RunAsync(4, async () => + { for (int i = 0; i < 100000; i++) { await lru.GetOrAddAsync(i + 1, i => Task.FromResult(i.ToString())); @@ -74,7 +76,8 @@ public async Task WhenSoakConcurrentGetWithArgCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int i = 0; i < 100000; i++) { // use the arg overload @@ -96,7 +99,8 @@ public async Task WhenSoakConcurrentGetAsyncWithArgCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.RunAsync(4, async () => { + await Threaded.RunAsync(4, async () => + { for (int i = 0; i < 100000; i++) { // use the arg overload @@ -118,7 +122,8 @@ public async Task WhenSoakConcurrentGetAndRemoveCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int i = 0; i < 100000; i++) { lru.TryRemove(i + 1); @@ -138,7 +143,8 @@ public async Task WhenSoakConcurrentGetAndRemoveKvpCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int i = 0; i < 100000; i++) { lru.TryRemove(new KeyValuePair<int, string>(i + 1, (i + 1).ToString())); @@ -158,7 +164,8 @@ public async Task WhenSoakConcurrentGetAndUpdateCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int i = 0; i < 100000; i++) { lru.TryUpdate(i + 1, i.ToString()); @@ -178,7 +185,8 @@ public async Task WhenSoakConcurrentGetAndAddCacheEndsInConsistentState() { for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int i = 0; i < 100000; i++) { lru.AddOrUpdate(i + 1, i.ToString()); @@ -200,7 +208,8 @@ public async Task WhenSoakConcurrentGetAndUpdateValueTypeCacheEndsInConsistentSt for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { var b = new byte[8]; for (int i = 0; i < 100000; i++) { @@ -240,7 +249,7 @@ await Threaded.Run(4, () => [Fact] public async Task WhenConcurrentUpdateAndRemoveKvp() { - TaskCompletionSource<int> tcs = new TaskCompletionSource<int> (); + TaskCompletionSource<int> tcs = new TaskCompletionSource<int>(); var removal = Task.Run(() => { @@ -266,7 +275,8 @@ public async Task WhenConcurrentUpdateAndRemoveKvp() [Repeat(10)] public async Task WhenConcurrentGetAndClearCacheEndsInConsistentState(int iteration) { - await Threaded.Run(4, r => { + await Threaded.Run(4, r => + { for (int i = 0; i < 100000; i++) { // clear 6,250 times per 1_000_000 iters @@ -289,7 +299,8 @@ await Threaded.Run(4, r => { [Repeat(10)] public async Task WhenConcurrentGetAndClearDuringWarmupCacheEndsInConsistentState(int iteration) { - await Threaded.Run(4, r => { + await Threaded.Run(4, r => + { for (int i = 0; i < 100000; i++) { // clear 25,000 times per 1_000_000 iters @@ -315,7 +326,7 @@ await Threaded.Run(4, r => { [Theory] [Repeat(10)] public async Task WhenValueIsBigStructNoLiveLock(int _) - { + { using var source = new CancellationTokenSource(); var started = new TaskCompletionSource<bool>(); var cache = new ConcurrentLru<int, Guid>(1, capacity, EqualityComparer<int>.Default); @@ -337,13 +348,13 @@ private void Setter(ICache<int, Guid> cache, CancellationToken cancelToken, Task cache.AddOrUpdate(1, Guid.NewGuid()); if (cancelToken.IsCancellationRequested) - { - return; + { + return; } } } - private void Checker(ICache<int, Guid> cache,CancellationTokenSource source) + private void Checker(ICache<int, Guid> cache, CancellationTokenSource source) { for (int count = 0; count < 100_000; ++count) { diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruTests.cs index dc8fd785..f1574c0c 100644 --- a/BitFaster.Caching.UnitTests/Lru/ConcurrentLruTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentLruTests.cs @@ -1,14 +1,14 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Threading.Tasks; +using BitFaster.Caching.Lru; +using FluentAssertions; using Xunit; using Xunit.Abstractions; -using System.Collections.Concurrent; -using System.Reflection; namespace BitFaster.Caching.UnitTests.Lru { @@ -705,7 +705,7 @@ public void WhenItemRemovedFromHotAfterWarmupItIsEagerlyCycledOut() Print(); // Hot [6,7,8] Warm [1,2,3] Cold [0,4,5] lru.Metrics.Value.Evicted.Should().Be(0); - + lru.GetOrAdd(-1, valueFactory.Create); lru.TryRemove(-1); @@ -862,7 +862,7 @@ public void WhenKeyDoesNotExistTryUpdateReturnsFalse() lru.TryUpdate(2, "3").Should().BeFalse(); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenKeyExistsTryUpdateIncrementsUpdateCount() @@ -905,9 +905,9 @@ public void WhenKeyExistsAddOrUpdateUpdatesExistingItem() [Fact] public void WhenKeyExistsAddOrUpdateGuidUpdatesExistingItem() - { - var lru2 = new ConcurrentLru<int, Guid>(1, capacity, EqualityComparer<int>.Default); - + { + var lru2 = new ConcurrentLru<int, Guid>(1, capacity, EqualityComparer<int>.Default); + var b = new byte[8]; lru2.AddOrUpdate(1, new Guid(1, 0, 0, b)); lru2.AddOrUpdate(1, new Guid(2, 0, 0, b)); @@ -941,7 +941,7 @@ public void WhenKeyDoesNotExistAddOrUpdateMaintainsLruOrder() lru.WarmCount.Should().Be(1); // items must have been enqueued and cycled for one of them to reach the warm queue } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenItemExistsAddOrUpdateFiresUpdateEvent() @@ -1054,7 +1054,7 @@ public void WhenItemsExistAndItemsAccessedClearRemovesAllItems(int itemCount) // By default capacity is 9. Test all possible states of touched items // in the cache. - for (int i = 0; i < itemCount; i++) + for (int i = 0; i < itemCount; i++) { lru.AddOrUpdate(i, "1"); } @@ -1081,16 +1081,16 @@ public void WhenItemsExistAndItemsAccessedClearRemovesAllItems(int itemCount) public void WhenWarmThenClearedIsWarmIsReset() { for (int i = 0; i < 20; i++) - { - lru.GetOrAdd(i, k => k.ToString()); + { + lru.GetOrAdd(i, k => k.ToString()); } lru.Clear(); lru.Count.Should().Be(0); for (int i = 0; i < 20; i++) - { - lru.GetOrAdd(i, k => k.ToString()); + { + lru.GetOrAdd(i, k => k.ToString()); } lru.Count.Should().Be(capacity.Hot + capacity.Warm + capacity.Cold); diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruSoakTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruSoakTests.cs index c8a1dda7..18a43f3e 100644 --- a/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruSoakTests.cs @@ -27,7 +27,8 @@ public ConcurrentTLruSoakTests(ITestOutputHelper testOutputHelper) [Repeat(10)] public async Task WhenSoakConcurrentGetCacheEndsInConsistentState(int iteration) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int j = 0; j < 100000; j++) { for (int i = 0; i < lru.Capacity; i++) diff --git a/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruTests.cs b/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruTests.cs index 5e91d18d..a1f355cc 100644 --- a/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/ConcurrentTLruTests.cs @@ -1,10 +1,10 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Generic; -using Xunit; using System.Runtime.InteropServices; +using BitFaster.Caching.Lru; using BitFaster.Caching.UnitTests.Retry; +using FluentAssertions; +using Xunit; using Xunit.Abstractions; namespace BitFaster.Caching.UnitTests.Lru diff --git a/BitFaster.Caching.UnitTests/Lru/DiscretePolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/DiscretePolicyTests.cs index 06c0ad5d..5e2d8e6c 100644 --- a/BitFaster.Caching.UnitTests/Lru/DiscretePolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/DiscretePolicyTests.cs @@ -11,7 +11,7 @@ public class DiscretePolicyTests private readonly TestExpiryCalculator<int, int> expiryCalculator; private readonly DiscretePolicy<int, int> policy; - public DiscretePolicyTests() + public DiscretePolicyTests() { expiryCalculator = new TestExpiryCalculator<int, int>(); policy = new DiscretePolicy<int, int>(expiryCalculator); @@ -36,13 +36,13 @@ public void CreateItemInitializesKeyValueAndTicks() { var timeToExpire = Duration.FromMinutes(60); - expiryCalculator.ExpireAfterCreate = (k, v) => + expiryCalculator.ExpireAfterCreate = (k, v) => { k.Should().Be(1); v.Should().Be(2); return timeToExpire; }; - + var item = this.policy.CreateItem(1, 2); item.Key.Should().Be(1); diff --git a/BitFaster.Caching.UnitTests/Lru/FastConcurrentLruTests.cs b/BitFaster.Caching.UnitTests/Lru/FastConcurrentLruTests.cs index 9c009f7c..3f387e05 100644 --- a/BitFaster.Caching.UnitTests/Lru/FastConcurrentLruTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/FastConcurrentLruTests.cs @@ -1,7 +1,7 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Generic; +using BitFaster.Caching.Lru; +using FluentAssertions; using Xunit; namespace BitFaster.Caching.UnitTests.Lru diff --git a/BitFaster.Caching.UnitTests/Lru/FastConcurrentTLruTests.cs b/BitFaster.Caching.UnitTests/Lru/FastConcurrentTLruTests.cs index 39b92577..85624150 100644 --- a/BitFaster.Caching.UnitTests/Lru/FastConcurrentTLruTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/FastConcurrentTLruTests.cs @@ -1,10 +1,10 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Generic; using System.Text; -using Xunit; using System.Threading.Tasks; +using BitFaster.Caching.Lru; +using FluentAssertions; +using Xunit; namespace BitFaster.Caching.UnitTests.Lru { diff --git a/BitFaster.Caching.UnitTests/Lru/LruInfoTests.cs b/BitFaster.Caching.UnitTests/Lru/LruInfoTests.cs index 133cb469..86264f60 100644 --- a/BitFaster.Caching.UnitTests/Lru/LruInfoTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/LruInfoTests.cs @@ -17,13 +17,13 @@ public void WhenExpiryNullGetExpiryReturnsNull() [Fact] public void WhenExpiryCalcValueTypeDoesNotMatchThrows() - { + { var info = new LruInfo<int>(); info.SetExpiry<int>(new TestExpiryCalculator<int, int>()); Action act = () => info.GetExpiry<string>(); - act.Should().Throw<InvalidOperationException>(); + act.Should().Throw<InvalidOperationException>(); } } } diff --git a/BitFaster.Caching.UnitTests/Lru/LruItemMemoryLayoutDumps.cs b/BitFaster.Caching.UnitTests/Lru/LruItemMemoryLayoutDumps.cs index a2ea5a43..60b6ca9b 100644 --- a/BitFaster.Caching.UnitTests/Lru/LruItemMemoryLayoutDumps.cs +++ b/BitFaster.Caching.UnitTests/Lru/LruItemMemoryLayoutDumps.cs @@ -36,7 +36,7 @@ public LruItemMemoryLayoutDumps(ITestOutputHelper testOutputHelper) //|=====================================| [Fact] public void DumpLruItem() - { + { var layout = TypeLayout.GetLayout<LruItem<object, object>>(includePaddings: true); testOutputHelper.WriteLine(layout.ToString()); } diff --git a/BitFaster.Caching.UnitTests/Lru/LruItemSoakTests.cs b/BitFaster.Caching.UnitTests/Lru/LruItemSoakTests.cs index 4bc949a6..fc8192e8 100644 --- a/BitFaster.Caching.UnitTests/Lru/LruItemSoakTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/LruItemSoakTests.cs @@ -17,7 +17,7 @@ public class LruItemSoakTests [Theory] [Repeat(soakIterations)] public async Task DetectTornStruct(int _) - { + { using var source = new CancellationTokenSource(); var started = new TaskCompletionSource<bool>(); @@ -38,8 +38,8 @@ private void Setter(CancellationToken cancelToken, TaskCompletionSource<bool> st item.SeqLockWrite(MassiveStruct.B); if (cancelToken.IsCancellationRequested) - { - return; + { + return; } } } @@ -53,16 +53,16 @@ private void Checker(CancellationTokenSource source) var t = item.SeqLockRead(); if (t != MassiveStruct.A && t != MassiveStruct.B) - { - throw new Exception($"Value is torn after {count} iterations"); + { + throw new Exception($"Value is torn after {count} iterations"); } } source.Cancel(); } - #pragma warning disable CS0659 // Object.Equals but no GetHashCode - #pragma warning disable CS0661 // operator== but no GetHashCode +#pragma warning disable CS0659 // Object.Equals but no GetHashCode +#pragma warning disable CS0661 // operator== but no GetHashCode public struct MassiveStruct : IEquatable<MassiveStruct> { // To repro on x64, struct should be larger than a cache line (64 bytes). @@ -79,8 +79,8 @@ public struct MassiveStruct : IEquatable<MassiveStruct> public long i; public static readonly MassiveStruct A = new MassiveStruct(); - public static readonly MassiveStruct B = new MassiveStruct() - { a = long.MaxValue, b = long.MaxValue, c = long.MaxValue, d = long.MaxValue, e = long.MaxValue, f= long.MaxValue, g = long.MaxValue, h = long.MaxValue, i = long.MaxValue }; + public static readonly MassiveStruct B = new MassiveStruct() + { a = long.MaxValue, b = long.MaxValue, c = long.MaxValue, d = long.MaxValue, e = long.MaxValue, f = long.MaxValue, g = long.MaxValue, h = long.MaxValue, i = long.MaxValue }; public override bool Equals(object obj) { @@ -110,7 +110,7 @@ public bool Equals(MassiveStruct other) return !(left == right); } } - #pragma warning restore CS0659 - #pragma warning restore CS0661 +#pragma warning restore CS0659 +#pragma warning restore CS0661 } } diff --git a/BitFaster.Caching.UnitTests/Lru/LruPolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/LruPolicyTests.cs index 16f8244e..57fd54a7 100644 --- a/BitFaster.Caching.UnitTests/Lru/LruPolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/LruPolicyTests.cs @@ -1,8 +1,8 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Generic; using System.Text; +using BitFaster.Caching.Lru; +using FluentAssertions; using Xunit; namespace BitFaster.Caching.UnitTests.Lru diff --git a/BitFaster.Caching.UnitTests/Lru/NoTelemetryPolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/NoTelemetryPolicyTests.cs index 9b75347c..128efec2 100644 --- a/BitFaster.Caching.UnitTests/Lru/NoTelemetryPolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/NoTelemetryPolicyTests.cs @@ -1,5 +1,5 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; +using BitFaster.Caching.Lru; +using FluentAssertions; using Xunit; namespace BitFaster.Caching.UnitTests.Lru diff --git a/BitFaster.Caching.UnitTests/Lru/StopwatchTickConverterTests.cs b/BitFaster.Caching.UnitTests/Lru/StopwatchTickConverterTests.cs index 86450e8a..f023cc83 100644 --- a/BitFaster.Caching.UnitTests/Lru/StopwatchTickConverterTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/StopwatchTickConverterTests.cs @@ -9,7 +9,7 @@ public class StopwatchTickConverterTests { [Fact] public void WhenConvertingToTicksIsReversable() - { + { var timespan = TimeSpan.FromSeconds(1); StopwatchTickConverter.FromTicks(StopwatchTickConverter.ToTicks(timespan)).Should().BeCloseTo(timespan, TimeSpan.FromMilliseconds(20)); diff --git a/BitFaster.Caching.UnitTests/Lru/TelemetryPolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/TelemetryPolicyTests.cs index 200322a7..6071e662 100644 --- a/BitFaster.Caching.UnitTests/Lru/TelemetryPolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/TelemetryPolicyTests.cs @@ -1,9 +1,9 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; +using System; using System.Collections.Generic; -using Xunit; +using BitFaster.Caching.Lru; +using FluentAssertions; using Moq; -using System; +using Xunit; namespace BitFaster.Caching.UnitTests.Lru { @@ -147,7 +147,7 @@ public void WhenEventSourceIsSetItemUpdatedEventUsesSource() eventSourceList[0].Should().Be(this); } -// backcompat: remove + // backcompat: remove #if NET [Fact] public void WhenInterfaceDefaultItemUpdatedRegisteredNoOp() diff --git a/BitFaster.Caching.UnitTests/Lru/TlruDateTimePolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/TlruDateTimePolicyTests.cs index faaf438d..c53f176c 100644 --- a/BitFaster.Caching.UnitTests/Lru/TlruDateTimePolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/TlruDateTimePolicyTests.cs @@ -1,11 +1,11 @@ -using FluentAssertions; -using FluentAssertions.Extensions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using BitFaster.Caching.Lru; +using FluentAssertions; +using FluentAssertions.Extensions; using Xunit; namespace BitFaster.Caching.UnitTests.Lru @@ -81,7 +81,7 @@ public void WhenItemIsNotExpiredShouldDiscardIsFalse() [Fact] public void CanDiscardIsTrue() - { + { this.policy.CanDiscard().Should().BeTrue(); } diff --git a/BitFaster.Caching.UnitTests/Lru/TlruStopwatchPolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/TlruStopwatchPolicyTests.cs index e2545f59..4b29a948 100644 --- a/BitFaster.Caching.UnitTests/Lru/TlruStopwatchPolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/TlruStopwatchPolicyTests.cs @@ -1,14 +1,14 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; -using System.Threading.Tasks; -using Xunit; +using System; using System.Diagnostics; +using System.Threading.Tasks; +using BitFaster.Caching.Lru; using BitFaster.Caching.UnitTests.Retry; +using FluentAssertions; +using Xunit; namespace BitFaster.Caching.UnitTests.Lru { -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if !NET public class TlruStopwatchPolicyTests { diff --git a/BitFaster.Caching.UnitTests/Lru/TlruTicksPolicyTests.cs b/BitFaster.Caching.UnitTests/Lru/TlruTicksPolicyTests.cs index 9b4a374d..814811f8 100644 --- a/BitFaster.Caching.UnitTests/Lru/TlruTicksPolicyTests.cs +++ b/BitFaster.Caching.UnitTests/Lru/TlruTicksPolicyTests.cs @@ -1,13 +1,13 @@ -using FluentAssertions; -using FluentAssertions.Extensions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Xunit; +using BitFaster.Caching.Lru; using BitFaster.Caching.UnitTests.Retry; +using FluentAssertions; +using FluentAssertions.Extensions; +using Xunit; namespace BitFaster.Caching.UnitTests.Lru { diff --git a/BitFaster.Caching.UnitTests/Retry/RetryFact.cs b/BitFaster.Caching.UnitTests/Retry/RetryFact.cs index efd42e94..2a796193 100644 --- a/BitFaster.Caching.UnitTests/Retry/RetryFact.cs +++ b/BitFaster.Caching.UnitTests/Retry/RetryFact.cs @@ -1,5 +1,5 @@ -using Xunit.Sdk; -using Xunit; +using Xunit; +using Xunit.Sdk; namespace BitFaster.Caching.UnitTests.Retry { diff --git a/BitFaster.Caching.UnitTests/Scheduler/BackgroundSchedulerTests.cs b/BitFaster.Caching.UnitTests/Scheduler/BackgroundSchedulerTests.cs index 75fc9d66..c47cc22f 100644 --- a/BitFaster.Caching.UnitTests/Scheduler/BackgroundSchedulerTests.cs +++ b/BitFaster.Caching.UnitTests/Scheduler/BackgroundSchedulerTests.cs @@ -56,7 +56,7 @@ public async Task WhenWorkDoesNotThrowLastExceptionIsEmpty() public async Task WhenWorkThrowsLastExceptionIsPopulated() { var tcs = new TaskCompletionSource<bool>(); - scheduler.Run(() => { tcs.SetResult(true); throw new InvalidCastException(); }); + scheduler.Run(() => { tcs.SetResult(true); throw new InvalidCastException(); }); await tcs.Task; await scheduler.WaitForExceptionAsync(); diff --git a/BitFaster.Caching.UnitTests/ScopedAsyncCacheTestBase.cs b/BitFaster.Caching.UnitTests/ScopedAsyncCacheTestBase.cs index 6bd50a76..faab6fe3 100644 --- a/BitFaster.Caching.UnitTests/ScopedAsyncCacheTestBase.cs +++ b/BitFaster.Caching.UnitTests/ScopedAsyncCacheTestBase.cs @@ -58,7 +58,7 @@ public void WhenRemovedEventHandlerIsRegisteredItIsFired() this.removedItems.First().Key.Should().Be(1); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenUpdatedEventHandlerIsRegisteredItIsFired() diff --git a/BitFaster.Caching.UnitTests/ScopedAsyncCacheTests.cs b/BitFaster.Caching.UnitTests/ScopedAsyncCacheTests.cs index 864287c6..e1261878 100644 --- a/BitFaster.Caching.UnitTests/ScopedAsyncCacheTests.cs +++ b/BitFaster.Caching.UnitTests/ScopedAsyncCacheTests.cs @@ -8,7 +8,7 @@ namespace BitFaster.Caching.UnitTests { public class ScopedAsyncCacheTests : ScopedAsyncCacheTestBase { - public ScopedAsyncCacheTests() + public ScopedAsyncCacheTests() : base(new ScopedAsyncCache<int, Disposable>(new ConcurrentLru<int, Scoped<Disposable>>(capacity))) { } @@ -52,7 +52,7 @@ public async Task GetOrAddAsyncDisposedScopeThrows() await getOrAdd.Should().ThrowAsync<InvalidOperationException>(); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public async Task GetOrAddAsyncArgDisposedScopeThrows() diff --git a/BitFaster.Caching.UnitTests/ScopedCacheSoakTests.cs b/BitFaster.Caching.UnitTests/ScopedCacheSoakTests.cs index 49b15190..a4a02b34 100644 --- a/BitFaster.Caching.UnitTests/ScopedCacheSoakTests.cs +++ b/BitFaster.Caching.UnitTests/ScopedCacheSoakTests.cs @@ -16,7 +16,8 @@ public async Task WhenSoakScopedGetOrAddValueIsAlwaysAlive() { for (int i = 0; i < 10; i++) { - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int j = 0; j < 100000; j++) { using (var l = this.cache.ScopedGetOrAdd(j, k => new Scoped<Disposable>(new Disposable(k)))) diff --git a/BitFaster.Caching.UnitTests/ScopedCacheTestBase.cs b/BitFaster.Caching.UnitTests/ScopedCacheTestBase.cs index dd41bda2..43a5a8a8 100644 --- a/BitFaster.Caching.UnitTests/ScopedCacheTestBase.cs +++ b/BitFaster.Caching.UnitTests/ScopedCacheTestBase.cs @@ -57,7 +57,7 @@ public void WhenRemovedEventHandlerIsRegisteredItIsFired() this.removedItems.First().Key.Should().Be(1); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenUpdatedEventHandlerIsRegisteredItIsFired() @@ -81,7 +81,7 @@ public void WhenKeyDoesNotExistAddOrUpdateAddsNewItem() lifetime.Value.Should().Be(d); } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER [Fact] public void WhenKeyDoesNotExistGetOrAddArgAddsValueWithArg() diff --git a/BitFaster.Caching.UnitTests/ScopedCacheTests.cs b/BitFaster.Caching.UnitTests/ScopedCacheTests.cs index 2345b48f..e13c19ac 100644 --- a/BitFaster.Caching.UnitTests/ScopedCacheTests.cs +++ b/BitFaster.Caching.UnitTests/ScopedCacheTests.cs @@ -11,7 +11,7 @@ namespace BitFaster.Caching.UnitTests { public class ScopedCacheTests : ScopedCacheTestBase { - public ScopedCacheTests() + public ScopedCacheTests() : base(new ScopedCache<int, Disposable>(new ConcurrentLru<int, Scoped<Disposable>>(capacity))) { } @@ -28,7 +28,7 @@ public void WhenInnerCacheIsNullCtorThrows() public void WhenScopeIsDisposedTryGetReturnsFalse() { var scope = new Scoped<Disposable>(new Disposable()); - + this.cache.ScopedGetOrAdd(1, k => scope); scope.Dispose(); @@ -49,7 +49,7 @@ public void GetOrAddDisposedScopeThrows() { var scope = new Scoped<Disposable>(new Disposable()); scope.Dispose(); - + Action getOrAdd = () => { this.cache.ScopedGetOrAdd(1, k => scope); }; getOrAdd.Should().Throw<InvalidOperationException>(); diff --git a/BitFaster.Caching.UnitTests/ScopedSoakTests.cs b/BitFaster.Caching.UnitTests/ScopedSoakTests.cs index 976f4b50..83930a67 100644 --- a/BitFaster.Caching.UnitTests/ScopedSoakTests.cs +++ b/BitFaster.Caching.UnitTests/ScopedSoakTests.cs @@ -14,7 +14,8 @@ public async Task WhenSoakCreateLifetimeScopeIsDisposedCorrectly() { var scope = new Scoped<Disposable>(new Disposable(i)); - await Threaded.Run(4, () => { + await Threaded.Run(4, () => + { for (int i = 0; i < 100000; i++) { using (var l = scope.CreateLifetime()) diff --git a/BitFaster.Caching.UnitTests/ScopedTests.cs b/BitFaster.Caching.UnitTests/ScopedTests.cs index 53fc4130..34a09338 100644 --- a/BitFaster.Caching.UnitTests/ScopedTests.cs +++ b/BitFaster.Caching.UnitTests/ScopedTests.cs @@ -1,7 +1,7 @@ -using FluentAssertions; -using BitFaster.Caching.Lru; -using System; +using System; using System.Collections.Generic; +using BitFaster.Caching.Lru; +using FluentAssertions; using Xunit; namespace BitFaster.Caching.UnitTests diff --git a/BitFaster.Caching.UnitTests/SingletonCacheTests.cs b/BitFaster.Caching.UnitTests/SingletonCacheTests.cs index d2871f17..61f42d87 100644 --- a/BitFaster.Caching.UnitTests/SingletonCacheTests.cs +++ b/BitFaster.Caching.UnitTests/SingletonCacheTests.cs @@ -162,11 +162,11 @@ public async Task DisposeOnManyDifferentThreadsAlwaysReturnsActiveValue() { var cache = new SingletonCache<string, DisposeTest>(); - var tasks = Enumerable.Range(0, 64).Select(i => Task.Run(() => - { + var tasks = Enumerable.Range(0, 64).Select(i => Task.Run(() => + { using (var handle = cache.Acquire("Foo")) - { - handle.Value.ThrowIfDisposed(); + { + handle.Value.ThrowIfDisposed(); } })); diff --git a/BitFaster.Caching.UnitTests/TestExpiryCalculator.cs b/BitFaster.Caching.UnitTests/TestExpiryCalculator.cs index 9cdd8ffe..e414de2a 100644 --- a/BitFaster.Caching.UnitTests/TestExpiryCalculator.cs +++ b/BitFaster.Caching.UnitTests/TestExpiryCalculator.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace BitFaster.Caching.UnitTests { diff --git a/BitFaster.Caching.UnitTests/Threaded.cs b/BitFaster.Caching.UnitTests/Threaded.cs index a3f575f5..81d4584f 100644 --- a/BitFaster.Caching.UnitTests/Threaded.cs +++ b/BitFaster.Caching.UnitTests/Threaded.cs @@ -21,7 +21,7 @@ public static async Task Run(int threadCount, Action<int> action) for (int i = 0; i < threadCount; i++) { - int run = i; + int run = i; tasks[i] = Task.Run(() => { mre.WaitOne(); diff --git a/BitFaster.Caching.UnitTests/Timed.cs b/BitFaster.Caching.UnitTests/Timed.cs index 9f04da9e..7d040e37 100644 --- a/BitFaster.Caching.UnitTests/Timed.cs +++ b/BitFaster.Caching.UnitTests/Timed.cs @@ -66,7 +66,7 @@ public static void Execute<TArg, TState>(TArg arg, Func<TArg, TState> first, Tim { third(state); return; - } + } } Thread.Sleep(200); diff --git a/BitFaster.Caching.UnitTests/TypePropsTests.cs b/BitFaster.Caching.UnitTests/TypePropsTests.cs index a02d9c80..d4770cd7 100644 --- a/BitFaster.Caching.UnitTests/TypePropsTests.cs +++ b/BitFaster.Caching.UnitTests/TypePropsTests.cs @@ -17,14 +17,14 @@ public class TypePropsTests [InlineData(typeof(long), true)] // this is only expected to pass on 64bit platforms [InlineData(typeof(Guid), false)] public void Test(Type argType, bool expected) - { + { var isWriteAtomic = method.MakeGenericMethod(argType); isWriteAtomic.Invoke(null, null).Should().BeOfType<bool>().Which.Should().Be(expected); } private static bool IsWriteAtomic<T>() - { + { return TypeProps<T>.IsWriteAtomic; } } diff --git a/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs b/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs index 7e3c0ce6..36f47759 100644 --- a/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs +++ b/BitFaster.Caching/Atomic/AtomicFactoryAsyncCache.cs @@ -153,8 +153,8 @@ public IEnumerator<KeyValuePair<K, V>> GetEnumerator() foreach (var kvp in this.cache) { if (kvp.Value.IsValueCreated) - { - yield return new KeyValuePair<K, V>(kvp.Key, kvp.Value.ValueIfCreated!); + { + yield return new KeyValuePair<K, V>(kvp.Key, kvp.Value.ValueIfCreated!); } } } diff --git a/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs b/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs index 60c9893f..c8d8fb5d 100644 --- a/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs +++ b/BitFaster.Caching/Atomic/AtomicFactoryScopedAsyncCache.cs @@ -148,8 +148,8 @@ public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator() foreach (var kvp in this.cache) { if (kvp.Value.IsScopeCreated) - { - yield return new KeyValuePair<K, Scoped<V>>(kvp.Key, kvp.Value.ScopeIfCreated!); + { + yield return new KeyValuePair<K, Scoped<V>>(kvp.Key, kvp.Value.ScopeIfCreated!); } } } diff --git a/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs b/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs index 2c3c2eb2..5730796b 100644 --- a/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs +++ b/BitFaster.Caching/Atomic/AtomicFactoryScopedCache.cs @@ -31,7 +31,7 @@ public AtomicFactoryScopedCache(ICache<K, ScopedAtomicFactory<K, V>> cache) Throw.ArgNull(ExceptionArgument.cache); this.cache = cache; - + if (cache.Events.HasValue) { this.events = new Optional<ICacheEvents<K, Scoped<V>>>(new EventProxy(cache.Events.Value!)); @@ -148,8 +148,8 @@ public IEnumerator<KeyValuePair<K, Scoped<V>>> GetEnumerator() foreach (var kvp in this.cache) { if (kvp.Value.IsScopeCreated) - { - yield return new KeyValuePair<K, Scoped<V>>(kvp.Key, kvp.Value.ScopeIfCreated!); + { + yield return new KeyValuePair<K, Scoped<V>>(kvp.Key, kvp.Value.ScopeIfCreated!); } } } @@ -161,7 +161,7 @@ IEnumerator IEnumerable.GetEnumerator() private class EventProxy : CacheEventProxyBase<K, ScopedAtomicFactory<K, V>, Scoped<V>> { - public EventProxy(ICacheEvents<K, ScopedAtomicFactory<K, V>> inner) + public EventProxy(ICacheEvents<K, ScopedAtomicFactory<K, V>> inner) : base(inner) { } diff --git a/BitFaster.Caching/Buffers/ArrayExtensions.cs b/BitFaster.Caching/Buffers/ArrayExtensions.cs index 9325247b..f83fda08 100644 --- a/BitFaster.Caching/Buffers/ArrayExtensions.cs +++ b/BitFaster.Caching/Buffers/ArrayExtensions.cs @@ -9,7 +9,7 @@ internal static class ArrayExtensions #if NETSTANDARD2_0 [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static T[] AsSpanOrArray<T>(this T[] array) - { + { return array; } diff --git a/BitFaster.Caching/Buffers/MpmcBoundedBuffer.cs b/BitFaster.Caching/Buffers/MpmcBoundedBuffer.cs index 76c87cc9..a0744f10 100644 --- a/BitFaster.Caching/Buffers/MpmcBoundedBuffer.cs +++ b/BitFaster.Caching/Buffers/MpmcBoundedBuffer.cs @@ -212,7 +212,7 @@ public BufferStatus TryAdd(T item) public void Clear() { while (TryTake(out _) != BufferStatus.Empty) - { + { } } diff --git a/BitFaster.Caching/Buffers/StripedMpscBuffer.cs b/BitFaster.Caching/Buffers/StripedMpscBuffer.cs index 8911b98f..aad3ec80 100644 --- a/BitFaster.Caching/Buffers/StripedMpscBuffer.cs +++ b/BitFaster.Caching/Buffers/StripedMpscBuffer.cs @@ -23,7 +23,7 @@ public sealed class StripedMpscBuffer<T> where T : class /// <param name="stripeCount">The stripe count.</param> /// <param name="bufferSize">The buffer size.</param> public StripedMpscBuffer(int stripeCount, int bufferSize) - { + { buffers = new MpscBoundedBuffer<T>[stripeCount]; for (var i = 0; i < stripeCount; i++) diff --git a/BitFaster.Caching/CacheEventProxyBase.cs b/BitFaster.Caching/CacheEventProxyBase.cs index bdfdb170..363a5130 100644 --- a/BitFaster.Caching/CacheEventProxyBase.cs +++ b/BitFaster.Caching/CacheEventProxyBase.cs @@ -61,7 +61,7 @@ private void RegisterUpdated(EventHandler<ItemUpdatedEventArgs<K, TOuter>> value { itemUpdatedProxy += value; -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER events.ItemUpdated += OnItemUpdated; #endif @@ -71,7 +71,7 @@ private void UnRegisterUpdated(EventHandler<ItemUpdatedEventArgs<K, TOuter>> val { this.itemUpdatedProxy -= value; -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER if (this.itemUpdatedProxy == null) { diff --git a/BitFaster.Caching/Counters/Striped64.cs b/BitFaster.Caching/Counters/Striped64.cs index 075cc4ec..370f6cd7 100644 --- a/BitFaster.Caching/Counters/Striped64.cs +++ b/BitFaster.Caching/Counters/Striped64.cs @@ -88,7 +88,7 @@ public abstract class Striped64 /// during table initialization races. Updated via CAS. /// </summary> protected PaddedLong @base = new(); - + /// <summary> /// When non-null, size is a power of 2. /// </summary> @@ -247,7 +247,7 @@ protected void LongAccumulate(long x, bool wasUncontended) } // Fall back on using base else if (this.@base.CompareAndSwap(v = this.@base.VolatileRead(), v + x)) - break; + break; } } } diff --git a/BitFaster.Caching/Disposer.cs b/BitFaster.Caching/Disposer.cs index 440cd198..26aa27ef 100644 --- a/BitFaster.Caching/Disposer.cs +++ b/BitFaster.Caching/Disposer.cs @@ -12,7 +12,7 @@ namespace BitFaster.Caching /// </summary> /// <typeparam name="T">The type of object to dispose</typeparam> public static class Disposer<T> - { + { /// <summary> /// Dispose value if it implements the IDisposable interface. /// </summary> diff --git a/BitFaster.Caching/Duration.cs b/BitFaster.Caching/Duration.cs index 8cc76832..daeb1fa6 100644 --- a/BitFaster.Caching/Duration.cs +++ b/BitFaster.Caching/Duration.cs @@ -36,8 +36,8 @@ public readonly struct Duration #endif internal Duration(long raw) - { - this.raw = raw; + { + this.raw = raw; } /// <summary> diff --git a/BitFaster.Caching/IAsyncCacheExt.cs b/BitFaster.Caching/IAsyncCacheExt.cs index 2187be54..99f3be4c 100644 --- a/BitFaster.Caching/IAsyncCacheExt.cs +++ b/BitFaster.Caching/IAsyncCacheExt.cs @@ -16,7 +16,7 @@ public interface IAsyncCacheExt<K, V> : IAsyncCache<K, V> // Following methods were also defined in ICache with default interface implementation which only works for // certain build targets, for other build targets we will define them within this new interface to avoid breaking // existing clients. -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if !NETCOREAPP3_0_OR_GREATER /// <summary> /// Adds a key/value pair to the cache if the key does not already exist. Returns the new value, or the diff --git a/BitFaster.Caching/ICacheEvents.cs b/BitFaster.Caching/ICacheEvents.cs index 80099d06..9e4a601a 100644 --- a/BitFaster.Caching/ICacheEvents.cs +++ b/BitFaster.Caching/ICacheEvents.cs @@ -12,7 +12,7 @@ public interface ICacheEvents<K, V> /// </summary> event EventHandler<ItemRemovedEventArgs<K, V>> ItemRemoved; -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER /// <summary> /// Occurs when an item is updated. diff --git a/BitFaster.Caching/ICacheExt.cs b/BitFaster.Caching/ICacheExt.cs index 612a5b89..164a6324 100644 --- a/BitFaster.Caching/ICacheExt.cs +++ b/BitFaster.Caching/ICacheExt.cs @@ -15,7 +15,7 @@ public interface ICacheExt<K, V> : ICache<K, V> // Following methods were also defined in ICache with default interface implementation which only works for // certain build targets, for other build targets we will define them within this new interface to avoid breaking // existing clients. -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if !NETCOREAPP3_0_OR_GREATER /// <summary> /// Adds a key/value pair to the cache if the key does not already exist. Returns the new value, or the diff --git a/BitFaster.Caching/ICacheMetrics.cs b/BitFaster.Caching/ICacheMetrics.cs index feb79589..e0b7461a 100644 --- a/BitFaster.Caching/ICacheMetrics.cs +++ b/BitFaster.Caching/ICacheMetrics.cs @@ -32,7 +32,7 @@ public interface ICacheMetrics /// </summary> long Evicted { get; } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER /// <summary> /// Gets the total number of updated items. diff --git a/BitFaster.Caching/Lfu/Builder/AsyncConcurrentLfuBuilder.cs b/BitFaster.Caching/Lfu/Builder/AsyncConcurrentLfuBuilder.cs index d009bc5d..c9751d67 100644 --- a/BitFaster.Caching/Lfu/Builder/AsyncConcurrentLfuBuilder.cs +++ b/BitFaster.Caching/Lfu/Builder/AsyncConcurrentLfuBuilder.cs @@ -28,7 +28,7 @@ public AsyncConcurrentLfuBuilder<K, V> WithExpireAfter(IExpiryCalculator<K, V> e ///<inheritdoc/> public override IAsyncCache<K, V> Build() { - return(ConcurrentLfuFactory.Create<K, V>(this.info) as IAsyncCache<K, V>)!; + return (ConcurrentLfuFactory.Create<K, V>(this.info) as IAsyncCache<K, V>)!; } } } diff --git a/BitFaster.Caching/Lfu/Builder/ScopedConcurrentLfuBuilder.cs b/BitFaster.Caching/Lfu/Builder/ScopedConcurrentLfuBuilder.cs index c477f210..814f9a62 100644 --- a/BitFaster.Caching/Lfu/Builder/ScopedConcurrentLfuBuilder.cs +++ b/BitFaster.Caching/Lfu/Builder/ScopedConcurrentLfuBuilder.cs @@ -10,7 +10,7 @@ namespace BitFaster.Caching.Lfu.Builder /// <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 K : notnull - where V : IDisposable + where V : IDisposable where W : IScoped<V> { private readonly ConcurrentLfuBuilder<K, W> inner; diff --git a/BitFaster.Caching/Lfu/CmSketch.cs b/BitFaster.Caching/Lfu/CmSketch.cs index 640e8ad6..d3fb3e06 100644 --- a/BitFaster.Caching/Lfu/CmSketch.cs +++ b/BitFaster.Caching/Lfu/CmSketch.cs @@ -11,7 +11,7 @@ public sealed class CmSketch<T> : CmSketchCore<T, DetectIsa> /// </summary> /// <param name="maximumSize">The maximum size.</param> /// <param name="comparer">The equality comparer.</param> - public CmSketch(long maximumSize, IEqualityComparer<T> comparer) + public CmSketch(long maximumSize, IEqualityComparer<T> comparer) : base(maximumSize, comparer) { } diff --git a/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs b/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs index 0191d1d9..8216a1e3 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfuBuilder.cs @@ -71,7 +71,7 @@ internal static ICache<K, V> Create<K, V>(LfuInfo<K> info) return (info.TimeToExpireAfterWrite.HasValue, info.TimeToExpireAfterAccess.HasValue, expiry != null) switch { - (true, false, false) => new ConcurrentTLfu<K, V>(info.ConcurrencyLevel, info.Capacity, info.Scheduler, info.KeyComparer, new ExpireAfterWrite<K,V>(info.TimeToExpireAfterWrite!.Value)), + (true, false, false) => new ConcurrentTLfu<K, V>(info.ConcurrencyLevel, info.Capacity, info.Scheduler, info.KeyComparer, new ExpireAfterWrite<K, V>(info.TimeToExpireAfterWrite!.Value)), (false, true, false) => new ConcurrentTLfu<K, V>(info.ConcurrencyLevel, info.Capacity, info.Scheduler, info.KeyComparer, new ExpireAfterAccess<K, V>(info.TimeToExpireAfterAccess!.Value)), (false, false, true) => new ConcurrentTLfu<K, V>(info.ConcurrencyLevel, info.Capacity, info.Scheduler, info.KeyComparer, expiry!), _ => new ConcurrentLfu<K, V>(info.ConcurrencyLevel, info.Capacity, info.Scheduler, info.KeyComparer) diff --git a/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs b/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs index f34a033f..0e4a3c3c 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs @@ -38,7 +38,7 @@ namespace BitFaster.Caching.Lfu /// </summary> /// Based on the Caffeine library by ben.manes@gmail.com (Ben Manes). /// https://github.com/ben-manes/caffeine - + internal struct ConcurrentLfuCore<K, V, N, P> : IBoundedPolicy where K : notnull where N : LfuNode<K, V> @@ -84,15 +84,15 @@ public ConcurrentLfuCore(int concurrencyLevel, int capacity, IScheduler schedule Throw.ArgOutOfRange(nameof(capacity)); int dictionaryCapacity = ConcurrentDictionarySize.Estimate(capacity); - this.dictionary = new (concurrencyLevel, dictionaryCapacity, comparer); + this.dictionary = new(concurrencyLevel, dictionaryCapacity, comparer); // cap concurrency at proc count * 2 int readStripes = Math.Min(BitOps.CeilingPowerOfTwo(concurrencyLevel), BitOps.CeilingPowerOfTwo(Environment.ProcessorCount * 2)); - this.readBuffer = new (readStripes, DefaultBufferSize); + this.readBuffer = new(readStripes, DefaultBufferSize); // Cap the write buffer to the cache size, or 128. Whichever is smaller. int writeBufferSize = Math.Min(BitOps.CeilingPowerOfTwo(capacity), 128); - this.writeBuffer = new (writeBufferSize); + this.writeBuffer = new(writeBufferSize); this.cmSketch = new CmSketch<K>(capacity, comparer); this.windowLru = new LfuNodeList<K, V>(); @@ -162,7 +162,7 @@ public void Trim(int itemCount) int lruCount = this.windowLru.Count + this.probationLru.Count + this.protectedLru.Count; itemCount = Math.Min(itemCount, lruCount); - candidates = new (itemCount); + candidates = new(itemCount); // Note: this is LRU order eviction, Caffeine is based on frequency // walk in lru order, get itemCount keys to evict @@ -309,8 +309,8 @@ void TryRemove(N node) #if NET6_0_OR_GREATER if (this.dictionary.TryRemove(new KeyValuePair<K, N>(node.Key, node))) #else - // https://devblogs.microsoft.com/pfxteam/little-known-gems-atomic-conditional-removals-from-concurrentdictionary/ - if (((ICollection<KeyValuePair<K, N>>)this.dictionary).Remove(new KeyValuePair<K, N>(node.Key, node))) + // https://devblogs.microsoft.com/pfxteam/little-known-gems-atomic-conditional-removals-from-concurrentdictionary/ + if (((ICollection<KeyValuePair<K, N>>)this.dictionary).Remove(new KeyValuePair<K, N>(node.Key, node))) #endif { node.WasRemoved = true; @@ -323,7 +323,7 @@ public bool TryRemove(KeyValuePair<K, V> item) if (this.dictionary.TryGetValue(item.Key, out var node)) { lock (node) - { + { if (EqualityComparer<V>.Default.Equals(node.Value, item.Value)) { var kvp = new KeyValuePair<K, N>(item.Key, node); @@ -370,10 +370,10 @@ public bool TryUpdate(K key, V value) if (this.dictionary.TryGetValue(key, out var node)) { lock (node) - { + { if (!node.WasRemoved) { - node.Value = value; + node.Value = value; // It's ok for this to be lossy, since the node is already tracked // and we will just lose ordering/hit count, but not orphan the node. @@ -409,8 +409,8 @@ private static void TakeCandidatesInLruOrder(LfuNodeList<K, V> lru, List<LfuNode { // LRUs can contain items that are already removed, skip those if (!curr.WasRemoved) - { - candidates.Add(curr); + { + candidates.Add(curr); } curr = curr.Next; @@ -519,7 +519,7 @@ private void TryScheduleDrain() } } } - + internal void DrainBuffers() { bool done = false; @@ -612,10 +612,10 @@ private void OnAccess(N node) switch (node.Position) { case Position.Window: - this.windowLru.MoveToEnd(node); + this.windowLru.MoveToEnd(node); break; case Position.Probation: - PromoteProbation(node); + PromoteProbation(node); break; case Position.Protected: this.protectedLru.MoveToEnd(node); @@ -884,7 +884,7 @@ public bool ShouldDrain(bool delayable) [MethodImpl(MethodImplOptions.AggressiveInlining)] public void VolatileWrite(int newStatus) - { + { Volatile.Write(ref this.drainStatus.Value, newStatus); } @@ -896,7 +896,7 @@ public void NonVolatileWrite(int newStatus) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Cas(int oldStatus, int newStatus) - { + { return Interlocked.CompareExchange(ref this.drainStatus.Value, newStatus, oldStatus) == oldStatus; } diff --git a/BitFaster.Caching/Lfu/ConcurrentTLfu.cs b/BitFaster.Caching/Lfu/ConcurrentTLfu.cs index b7c12051..439fddf1 100644 --- a/BitFaster.Caching/Lfu/ConcurrentTLfu.cs +++ b/BitFaster.Caching/Lfu/ConcurrentTLfu.cs @@ -158,7 +158,8 @@ private CachePolicy CreatePolicy() default: afterCustom = new Optional<IDiscreteTimePolicy>(this); break; - }; + } + ; return new CachePolicy(new Optional<IBoundedPolicy>(this), afterWrite, afterAccess, afterCustom); } diff --git a/BitFaster.Caching/Lfu/LfuCapacityPartition.cs b/BitFaster.Caching/Lfu/LfuCapacityPartition.cs index e56b3cb2..e89e883a 100644 --- a/BitFaster.Caching/Lfu/LfuCapacityPartition.cs +++ b/BitFaster.Caching/Lfu/LfuCapacityPartition.cs @@ -10,7 +10,7 @@ namespace BitFaster.Caching.Lfu public sealed class LfuCapacityPartition { private readonly int max; - + private int windowCapacity; private int protectedCapacity; private int probationCapacity; diff --git a/BitFaster.Caching/Lfu/LfuNode.cs b/BitFaster.Caching/Lfu/LfuNode.cs index de5b7ce7..71842205 100644 --- a/BitFaster.Caching/Lfu/LfuNode.cs +++ b/BitFaster.Caching/Lfu/LfuNode.cs @@ -27,29 +27,29 @@ public LfuNode(K k, V v) public readonly K Key; - public V Value - { + public V Value + { [MethodImpl(MethodImplOptions.AggressiveInlining)] get - { + { if (TypeProps<V>.IsWriteAtomic) - { + { return data; } else - { + { return SeqLockRead(); - } + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] set - { + { if (TypeProps<V>.IsWriteAtomic) - { + { data = value; } else - { + { SeqLockWrite(value); } } @@ -93,13 +93,13 @@ internal void Invalidate() } internal V SeqLockRead() - { + { var spin = new SpinWait(); while (true) - { + { var start = Volatile.Read(ref this.sequence); - if ((start & 1) == 1) + if ((start & 1) == 1) { // A write is in progress, spin. spin.SpinOnce(); @@ -110,15 +110,15 @@ internal V SeqLockRead() var end = Volatile.Read(ref this.sequence); if (start == end) - { - return copy; + { + return copy; } } } // Note: LfuNode should be locked while invoking this method. Multiple writer threads are not supported. internal void SeqLockWrite(V value) - { + { Interlocked.Increment(ref sequence); this.data = value; @@ -154,8 +154,8 @@ public TimeOrderNode(K k, V v) : base(k, v) { } - public Duration TimeToExpire - { + public Duration TimeToExpire + { get => timeToExpire; set => timeToExpire = value; } diff --git a/BitFaster.Caching/Lfu/LfuNodeList.cs b/BitFaster.Caching/Lfu/LfuNodeList.cs index 5ce6dd1b..3498df5c 100644 --- a/BitFaster.Caching/Lfu/LfuNodeList.cs +++ b/BitFaster.Caching/Lfu/LfuNodeList.cs @@ -186,7 +186,7 @@ public bool MoveNext() { node = null; } - + return true; } diff --git a/BitFaster.Caching/Lfu/TimerWheel.cs b/BitFaster.Caching/Lfu/TimerWheel.cs index 6f09fa72..cc4675a5 100644 --- a/BitFaster.Caching/Lfu/TimerWheel.cs +++ b/BitFaster.Caching/Lfu/TimerWheel.cs @@ -51,7 +51,7 @@ public TimerWheel() for (int j = 0; j < wheels[i].Length; j++) { - wheels[i][j] = TimeOrderNode< K, V>.CreateSentinel(); + wheels[i][j] = TimeOrderNode<K, V>.CreateSentinel(); } } } @@ -84,12 +84,12 @@ public void Advance<N, P>(ref ConcurrentLfuCore<K, V, N, P> cache, Duration curr long previousTicks = (long)(((ulong)previousTime) >> TimerWheel.Shift[i]); long currentTicks = (long)(((ulong)currentTime.raw) >> TimerWheel.Shift[i]); long delta = (currentTicks - previousTicks); - + if (delta <= 0L) { break; } - + Expire(ref cache, i, previousTicks, delta); } } @@ -281,7 +281,7 @@ private long PeekAhead(int index) TimeOrderNode<K, V> sentinel = timerWheel[probe]; TimeOrderNode<K, V> next = sentinel.GetNextInTimeOrder(); - return (next == sentinel) ? long.MaxValue: (TimerWheel.Spans[index] - (time & spanMask)); + return (next == sentinel) ? long.MaxValue : (TimerWheel.Spans[index] - (time & spanMask)); } } } diff --git a/BitFaster.Caching/Lru/Builder/LruInfo.cs b/BitFaster.Caching/Lru/Builder/LruInfo.cs index ba69b5da..c1ffeb21 100644 --- a/BitFaster.Caching/Lru/Builder/LruInfo.cs +++ b/BitFaster.Caching/Lru/Builder/LruInfo.cs @@ -43,7 +43,7 @@ public sealed class LruInfo<K> /// Get the custom expiry. /// </summary> /// <returns>The expiry.</returns> - public IExpiryCalculator<K, V>? GetExpiry<V>() + public IExpiryCalculator<K, V>? GetExpiry<V>() { if (this.expiry == null) { @@ -52,8 +52,8 @@ public sealed class LruInfo<K> var e = this.expiry as IExpiryCalculator<K, V>; - if (e == null) - Throw.InvalidOp($"Incompatible IExpiryCalculator value generic type argument, expected {typeof(IExpiryCalculator<K,V>)} but found {this.expiry.GetType()}"); + if (e == null) + Throw.InvalidOp($"Incompatible IExpiryCalculator value generic type argument, expected {typeof(IExpiryCalculator<K, V>)} but found {this.expiry.GetType()}"); return e; } diff --git a/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs b/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs index 01f4445d..4d826808 100644 --- a/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs +++ b/BitFaster.Caching/Lru/Builder/ScopedConcurrentLruBuilder.cs @@ -10,7 +10,7 @@ namespace BitFaster.Caching.Lru.Builder /// <typeparam name="W">The type of the wrapped cache value.</typeparam> public sealed class ScopedConcurrentLruBuilder<K, V, W> : LruBuilderBase<K, V, ScopedConcurrentLruBuilder<K, V, W>, IScopedCache<K, V>> where K : notnull - where V : IDisposable + where V : IDisposable where W : IScoped<V> { private readonly ConcurrentLruBuilder<K, W> inner; diff --git a/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs b/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs index c9932106..5510e344 100644 --- a/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs +++ b/BitFaster.Caching/Lru/ConcurrentLruBuilderExtensions.cs @@ -1,6 +1,6 @@ using System; -using BitFaster.Caching.Lru.Builder; using BitFaster.Caching.Atomic; +using BitFaster.Caching.Lru.Builder; namespace BitFaster.Caching.Lru { diff --git a/BitFaster.Caching/Lru/ConcurrentLruCore.cs b/BitFaster.Caching/Lru/ConcurrentLruCore.cs index 6e66987c..76f979f6 100644 --- a/BitFaster.Caching/Lru/ConcurrentLruCore.cs +++ b/BitFaster.Caching/Lru/ConcurrentLruCore.cs @@ -147,8 +147,8 @@ public IEnumerator<KeyValuePair<K, V>> GetEnumerator() foreach (var kvp in this.dictionary) { if (!itemPolicy.ShouldDiscard(kvp.Value)) - { - yield return new KeyValuePair<K, V>(kvp.Key, kvp.Value.Value); + { + yield return new KeyValuePair<K, V>(kvp.Key, kvp.Value.Value); } } } @@ -390,7 +390,7 @@ public bool TryUpdate(K key, V value) existing.Value = value; this.itemPolicy.Update(existing); -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER this.telemetryPolicy.OnItemUpdated(existing.Key, oldValue, existing.Value); #endif @@ -481,7 +481,7 @@ private void TrimExpired() lock (this.dictionary) { this.TrimAllDiscardedItems(); - } + } } } @@ -924,7 +924,7 @@ public Proxy(ConcurrentLruCore<K, V, I, P, T> lru) public long Evicted => lru.telemetryPolicy.Evicted; -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER public long Updated => lru.telemetryPolicy.Updated; #endif @@ -938,7 +938,7 @@ public event EventHandler<ItemRemovedEventArgs<K, V>> ItemRemoved remove { this.lru.telemetryPolicy.ItemRemoved -= value; } } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER public event EventHandler<ItemUpdatedEventArgs<K, V>> ItemUpdated { diff --git a/BitFaster.Caching/Lru/ITelemetryPolicy.cs b/BitFaster.Caching/Lru/ITelemetryPolicy.cs index 27d991cf..420175b8 100644 --- a/BitFaster.Caching/Lru/ITelemetryPolicy.cs +++ b/BitFaster.Caching/Lru/ITelemetryPolicy.cs @@ -27,7 +27,7 @@ public interface ITelemetryPolicy<K, V> : ICacheMetrics, ICacheEvents<K, V> /// <param name="reason">The reason for removal.</param> void OnItemRemoved(K key, V value, ItemRemovedReason reason); -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER /// <summary> /// Register the update of an item. diff --git a/BitFaster.Caching/Lru/ItemDestination.cs b/BitFaster.Caching/Lru/ItemDestination.cs index 9481ef56..d0e872b0 100644 --- a/BitFaster.Caching/Lru/ItemDestination.cs +++ b/BitFaster.Caching/Lru/ItemDestination.cs @@ -20,5 +20,5 @@ public enum ItemDestination /// Remove the item. /// </summary> Remove - } + } } diff --git a/BitFaster.Caching/Lru/LruItem.cs b/BitFaster.Caching/Lru/LruItem.cs index 66743cfc..5f1ed5c2 100644 --- a/BitFaster.Caching/Lru/LruItem.cs +++ b/BitFaster.Caching/Lru/LruItem.cs @@ -39,29 +39,29 @@ public LruItem(K k, V v) /// <summary> /// Gets or sets the value. /// </summary> - public V Value - { + public V Value + { [MethodImpl(MethodImplOptions.AggressiveInlining)] get - { + { if (TypeProps<V>.IsWriteAtomic) - { + { return data; } else - { + { return SeqLockRead(); - } + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] set - { + { if (TypeProps<V>.IsWriteAtomic) - { + { data = value; } else - { + { SeqLockWrite(value); } } @@ -89,21 +89,21 @@ public bool WasRemoved /// Marks the item as accessed, if it was not already accessed. /// </summary> public void MarkAccessed() - { + { if (!this.wasAccessed) - { - this.wasAccessed = true; + { + this.wasAccessed = true; } } internal V SeqLockRead() - { + { var spin = new SpinWait(); while (true) - { + { var start = Volatile.Read(ref this.sequence); - if ((start & 1) == 1) + if ((start & 1) == 1) { // A write is in progress, spin. spin.SpinOnce(); @@ -114,15 +114,15 @@ internal V SeqLockRead() var end = Volatile.Read(ref this.sequence); if (start == end) - { - return copy; + { + return copy; } } } // Note: LruItem should be locked while invoking this method. Multiple writer threads are not supported. internal void SeqLockWrite(V value) - { + { Interlocked.Increment(ref sequence); this.data = value; diff --git a/BitFaster.Caching/Lru/Time.cs b/BitFaster.Caching/Lru/Time.cs index 8ca96c04..245f240e 100644 --- a/BitFaster.Caching/Lru/Time.cs +++ b/BitFaster.Caching/Lru/Time.cs @@ -22,11 +22,11 @@ internal class Time /// <summary> /// Gets or sets the last time. /// </summary> - internal long Last + internal long Last { [MethodImpl(MethodImplOptions.AggressiveInlining)] get - { + { if (Is64Bit) { return time; diff --git a/BitFaster.Caching/Optional.cs b/BitFaster.Caching/Optional.cs index fa4c56a0..24f30606 100644 --- a/BitFaster.Caching/Optional.cs +++ b/BitFaster.Caching/Optional.cs @@ -6,7 +6,7 @@ namespace BitFaster.Caching /// Represents an optional value. /// </summary> [DebuggerDisplay("{Value}")] - public class Optional<T> + public class Optional<T> { private readonly T? value; private readonly bool hasValue; diff --git a/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs b/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs index 42b303d2..b7c64cc0 100644 --- a/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs +++ b/BitFaster.Caching/Scheduler/BackgroundThreadScheduler.cs @@ -79,7 +79,7 @@ private async Task Background() { action!(); } - else + else { spinner.SpinOnce(); } diff --git a/BitFaster.Caching/ScopedAsyncCache.cs b/BitFaster.Caching/ScopedAsyncCache.cs index 9fae539d..fa13a1f5 100644 --- a/BitFaster.Caching/ScopedAsyncCache.cs +++ b/BitFaster.Caching/ScopedAsyncCache.cs @@ -86,7 +86,7 @@ public async ValueTask<Lifetime<V>> ScopedGetOrAddAsync(K key, Func<K, Task<Scop } } -// backcompat: remove conditional compile + // backcompat: remove conditional compile #if NETCOREAPP3_0_OR_GREATER /// <summary> /// Adds a key/scoped value pair to the cache if the key does not already exist. Returns a lifetime for either diff --git a/BitFaster.Caching/Throw.cs b/BitFaster.Caching/Throw.cs index 9870e697..99485767 100644 --- a/BitFaster.Caching/Throw.cs +++ b/BitFaster.Caching/Throw.cs @@ -41,7 +41,7 @@ internal static class Throw [MethodImpl(MethodImplOptions.NoInlining)] private static InvalidOperationException CreateScopedRetryFailure() => new InvalidOperationException(ScopedCacheDefaults.RetryFailureMessage); - + [MethodImpl(MethodImplOptions.NoInlining)] private static ObjectDisposedException CreateObjectDisposedException<T>() => new ObjectDisposedException(typeof(T).Name);