Conversation
…te to TKey Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/29f900ac-3870-4bdc-9517-6807d80f09b5 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
bitfaster
April 11, 2026 03:36
View session
There was a problem hiding this comment.
Pull request overview
Updates the alternate-key lookup APIs so GetOrAdd/GetOrAddAsync value factories receive the canonical cache key type (TKey) rather than the alternate key type (TAlternateKey), and propagates that change through implementations and tests.
Changes:
- Change
IAlternateLookup/IAsyncAlternateLookupfactory delegate signatures fromFunc<TAlternateKey,…>toFunc<TKey,…>. - Update LRU/LFU/Atomic alternate-lookup implementations to pass
actualKey(TKey) into the factory. - Update unit/soak tests to use the new
TKeyfactory parameter type.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| BitFaster.Caching/Lru/ConcurrentLruCore.cs | Passes actualKey (K) into sync/async alternate-lookup factories. |
| BitFaster.Caching/Lru/ClassicLru.cs | Passes actualKey (K) into sync/async alternate-lookup factories. |
| BitFaster.Caching/Lfu/ConcurrentLfuCore.cs | Passes actualKey (K) into sync/async alternate-lookup factories. |
| BitFaster.Caching/IAsyncAlternateLookup.cs | Changes async factory delegate types to Func<TKey,…>. |
| BitFaster.Caching/IAlternateLookup.cs | Changes sync factory delegate types to Func<TKey,…>. |
| BitFaster.Caching/Atomic/AtomicFactoryCache.cs | Updates alternate-lookup adapter to accept Func<K,…> factories. |
| BitFaster.Caching.UnitTests/Lru/ConcurrentLruSoakTests.cs | Updates alternate-lookup soak factories to accept string key input. |
| BitFaster.Caching.UnitTests/Lru/ConcurrentLruAsyncAlternateLookupTests.cs | Updates async factory lambdas to use TKey parameter. |
| BitFaster.Caching.UnitTests/Lru/ConcurrentLruAlternateLookupTests.cs | Updates sync factory lambdas to use TKey parameter. |
| BitFaster.Caching.UnitTests/Lru/ClassicLruAsyncAlternateLookupTests.cs | Updates async factory lambdas to use TKey parameter. |
| BitFaster.Caching.UnitTests/Lru/ClassicLruAlternateLookupTests.cs | Updates sync factory lambdas to use TKey parameter. |
| BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuAsyncAlternateLookupTests.cs | Updates async factory lambdas to use TKey parameter. |
| BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuAlternateLookupTests.cs | Updates sync factory lambdas to use TKey parameter. |
| BitFaster.Caching.UnitTests/Atomic/AtomicFactoryCacheAlternateLookupTests.cs | Updates sync factory lambdas to use TKey parameter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
42
to
46
| var result = await alternate.GetOrAddAsync("42".AsSpan(), key => | ||
| { | ||
| factoryCalls++; | ||
| return Task.FromResult($"value-{key.ToString()}"); | ||
| return Task.FromResult($"value-{key}"); | ||
| }); |
Comment on lines
42
to
46
| var result = await alternate.GetOrAddAsync("42".AsSpan(), key => | ||
| { | ||
| factoryCalls++; | ||
| return Task.FromResult($"value-{key.ToString()}"); | ||
| return Task.FromResult($"value-{key}"); | ||
| }); |
Comment on lines
60
to
64
| alternate.GetOrAdd(key, key => | ||
| { | ||
| factoryCalls++; | ||
| return $"value-{key.ToString()}"; | ||
| return $"value-{key}"; | ||
| }).Should().Be("value-42"); |
Owner
|
@copilot fix the build, update the xml doc issues in the code review and ensure all tests pass. |
…rom AlternateKey to ActualKey Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/880908de-2e9a-47de-a736-2080c1044131 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Contributor
Author
Done in d5c3b16:
|
Owner
|
@copilot fix the benchmark so it can build and run. |
…har>, int> to Func<string, int> Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/8e228955-be34-438b-b930-aba65302bb90 Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Contributor
Author
bitfaster
approved these changes
Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes the type of the value factory input argument in
IAlternateLookupandIAsyncAlternateLookupfromTAlternateKeytoTKey.Previously
GetOrAdd/GetOrAddAsyncpassed the alternate key (e.g.ReadOnlySpan<char>) into the value factory. After this change the canonical cache key (TKey, e.g.string) is passed instead. This is more useful since the factory typically needs the strongly-typed key to produce the value, and it also avoids passing a potentially short-livedref structinto a callback.Changes
Interfaces
IAlternateLookup<TAlternateKey, TKey, TValue>–GetOrAdd/GetOrAdd<TArg>factory signatures changed fromFunc<TAlternateKey, …>toFunc<TKey, …>IAsyncAlternateLookup<TAlternateKey, TKey, TValue>–GetOrAddAsync/GetOrAddAsync<TArg>factory signatures changed fromFunc<TAlternateKey, …>toFunc<TKey, …>Implementations – all now pass
actualKey(TKey) to the factory instead ofkey(TAlternateKey):ConcurrentLruCore.cs(AlternateLookup & AsyncAlternateLookup structs)ClassicLru.cs(AlternateLookup struct)ConcurrentLfuCore.cs(AlternateLookup struct)AtomicFactoryCache.cs(AlternateLookup struct)Tests – updated factory lambdas to use
TKeyparameter:ConcurrentLruAlternateLookupTests,ClassicLruAlternateLookupTestsConcurrentLruAsyncAlternateLookupTests,ClassicLruAsyncAlternateLookupTestsConcurrentLfuAlternateLookupTests,ConcurrentLfuAsyncAlternateLookupTestsAtomicFactoryCacheAlternateLookupTestsConcurrentLruSoakTests