Skip to content

Add IAsyncAlternateLookup support to ConcurrentLfu#744

Open
Copilot wants to merge 2 commits intomainfrom
copilot/implement-iasyncalternatelookup
Open

Add IAsyncAlternateLookup support to ConcurrentLfu#744
Copilot wants to merge 2 commits intomainfrom
copilot/implement-iasyncalternatelookup

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Adds IAsyncAlternateLookup support to ConcurrentLfu and ConcurrentTLfu, mirroring the existing implementation on ConcurrentLru.

Core changes

  • ConcurrentLfuCore.cs: AlternateLookup<TAlternateKey> now implements both IAlternateLookup and IAsyncAlternateLookup in a single struct. Adds GetOrAddAsync, GetOrAddAsync<TArg>, and a private GetOrAddAsyncSlow helper. Since TAlternateKey allows ref struct, the public methods are non-async wrappers that capture the ref struct before delegating to the async slow path via a plain K key.
  • ConcurrentLfu.cs: Exposes GetAsyncAlternateLookup<TAlternateKey>() and TryGetAsyncAlternateLookup<TAlternateKey>().
  • ConcurrentTLfu.cs: Exposes GetAsyncAlternateLookup<TAlternateKey>() and TryGetAsyncAlternateLookup<TAlternateKey>(), delegating to the inner core, matching ConcurrentLfu.

Tests

  • ConcurrentLfuAsyncAlternateLookupTests.cs (new): unit tests for comparer compatibility, and GetOrAddAsync/GetOrAddAsync<TArg> miss+hit behaviour.
  • ConcurrentTLfuTests.cs: unit tests for GetAsyncAlternateLookup and TryGetAsyncAlternateLookup covering compatible and incompatible comparer cases.
  • ConcurrentLfuSoakTests.cs: two new concurrent soak tests for GetOrAddAsync and GetOrAddAsync<TArg> using ReadOnlySpan<char> keys.

Usage

var cache = new ConcurrentLfu<string, Data>(1, 1000, scheduler, StringComparer.Ordinal);
var lookup = cache.GetAsyncAlternateLookup<ReadOnlySpan<char>>();

ReadOnlySpan<char> key = "some-key".AsSpan();
var value = await lookup.GetOrAddAsync(key, static k => FetchAsync(k.ToString()));

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@bitfaster bitfaster linked an issue Mar 30, 2026 that may be closed by this pull request
@bitfaster bitfaster changed the title Implement IAsyncAlternateLookup for ConcurrentLfu Add IAsyncAlternateLookup support to ConcurrentLfu Mar 30, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented Mar 30, 2026

Coverage Status

coverage: 99.158% (+0.04%) from 99.118%
when pulling d02e3a8 on copilot/implement-iasyncalternatelookup
into 0ec5a06 on main.

@bitfaster
Copy link
Copy Markdown
Owner

@copilot Add the GetAsyncAlternateLookup and TryGetAsyncAlternateLookup methods to ConcurrentTLfu, matching ConcurrentLfu. Add simple unit tests for ConcurrentTLfu to verify the correct object is returned and they are wired up to the inner class.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 30, 2026

@copilot Add the GetAsyncAlternateLookup and TryGetAsyncAlternateLookup methods to ConcurrentTLfu, matching ConcurrentLfu. Add simple unit tests for ConcurrentTLfu to verify the correct obje...

Done in d02e3a8. Added GetAsyncAlternateLookup and TryGetAsyncAlternateLookup to ConcurrentTLfu, both delegating to core, matching the pattern used in ConcurrentLfu. Added 4 unit tests to ConcurrentTLfuTests.cs covering compatible/incompatible comparer cases for both methods.

Copilot AI changed the title Add IAsyncAlternateLookup support to ConcurrentLfu Add IAsyncAlternateLookup support to ConcurrentLfu and ConcurrentTLfu Mar 30, 2026
Copilot AI requested a review from bitfaster March 30, 2026 06:32
@bitfaster bitfaster changed the title Add IAsyncAlternateLookup support to ConcurrentLfu and ConcurrentTLfu Add IAsyncAlternateLookup support to ConcurrentLfu Mar 30, 2026
@bitfaster bitfaster marked this pull request as ready for review March 30, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Add alternate lookup support

3 participants