Conversation
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/dccf8c03-48f8-4e76-bf28-f77f9a51d303 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/dccf8c03-48f8-4e76-bf28-f77f9a51d303 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
| } | ||
| #pragma warning restore CA2000 // Dispose objects before losing scope | ||
|
|
||
| public Lifetime<V> ScopedGetOrAdd(TAlternateKey key, Func<K, Scoped<V>> valueFactory) |
There was a problem hiding this comment.
@copilot add a soak test to verify this works as expected with concurrent callers. Soak test will cover all branches in the private ScopedGetOrAdd method.
There was a problem hiding this comment.
Added a concurrent soak test in ScopedCacheSoakTests that races alternate lookup ScopedGetOrAdd against TryRemove and asserts the returned lifetime stays alive under contention, covering the retry path in the private helper. Addressed in a3558be.
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/72ba7d13-f135-44e5-ab2e-e3421636eee4 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/72ba7d13-f135-44e5-ab2e-e3421636eee4 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
| [Fact] | ||
| public async Task ScopedGetOrAdd_ConcurrentWithRemove_ReturnedLifetimeIsAlive() | ||
| { | ||
| var scopedCache = new ScopedCache<string, Disposable>(new ConcurrentLru<string, Scoped<Disposable>>(1, 1, StringComparer.Ordinal)); |
There was a problem hiding this comment.
@copilot initialize the cache with the same size parameter as the other tests, 1 is an invalid size. Do not remove values as part of the test. Instead, make the test match WhenSoakScopedGetOrAddValueIsAlwaysAlive but use the alternate lookup.
There was a problem hiding this comment.
Updated the soak test to use the standard cache capacity and to mirror the existing scoped get-or-add soak pattern via alternate lookup, without removing values. Addressed in 99d95c4.
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/53059f04-e895-4186-a464-9cd3159d01ec Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
| { | ||
| for (int j = 0; j < 100000; j++) | ||
| { | ||
| string key = j.ToString(); |
There was a problem hiding this comment.
@copilot declare a char[] buffer variable and format j into the buffer to avoid allocating a string in the loop.
There was a problem hiding this comment.
Updated the soak test to reuse one char[] buffer per worker thread via Threaded.Run(threadCount, r => ...), so the key formatting no longer allocates in the hot loop. Addressed in 32705c1.
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/7b7e1bc4-582b-4e81-b6a3-d21883ba1a98 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/7b7e1bc4-582b-4e81-b6a3-d21883ba1a98 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/7b7e1bc4-582b-4e81-b6a3-d21883ba1a98 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
| { | ||
| await Threaded.Run(threadCount, r => | ||
| { | ||
| var key = keys[r]; |
There was a problem hiding this comment.
@copilot declare the key on this line and delete the array of keys. This will avoid capturing the keys array in the lambda.
There was a problem hiding this comment.
Updated it to declare the per-thread char[] buffer inside the worker lambda and removed the outer keys array, so the lambda no longer captures that array. Addressed in 330d9bf.
Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/430078a5-1591-4951-9db4-852f58455984 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Summary
IScopedAlternateLookupAPI and expose it fromIScopedCacheScopedCacheandAtomicFactoryScopedCacheValidation
dotnet format BitFaster.Caching/BitFaster.Caching.csprojdotnet build BitFaster.Caching/BitFaster.Caching.csproj -f net9.0dotnet test BitFaster.Caching.UnitTests/BitFaster.Caching.UnitTests.csproj -f net9.0parallel_validation