Skip to content

Add IAlternateLookup support to ClassicLru#742

Merged
bitfaster merged 3 commits intomainfrom
copilot/add-ialternatelookup-to-classiclru
Mar 30, 2026
Merged

Add IAlternateLookup support to ClassicLru#742
bitfaster merged 3 commits intomainfrom
copilot/add-ialternatelookup-to-classiclru

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

  • Add GetAlternateLookup<TAlternateKey>() and TryGetAlternateLookup<TAlternateKey>() methods to ClassicLru<K,V> (NET9_0_OR_GREATER)
  • Add inner AlternateLookup<TAlternateKey> struct implementing IAlternateLookup<TAlternateKey, K, V> with TryGet, TryRemove, TryUpdate, AddOrUpdate, GetOrAdd, GetOrAdd<TArg>
  • Add unit tests in ClassicLruAlternateLookupTests.cs (9 tests - all passing)
  • Run dotnet format
  • Build and test (56 existing ClassicLru tests + 9 new tests all pass)
  • Code review and security scan (no issues found)

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 30, 2026

Coverage Status

coverage: 99.111% (-0.05%) from 99.158%
when pulling 36c2368 on copilot/add-ialternatelookup-to-classiclru
into 68720da on main.

@bitfaster bitfaster linked an issue Mar 30, 2026 that may be closed by this pull request

if (this.alternate.TryGetValue(key, out var node))
{
this.lru.LockAndMoveToEnd(node);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot extract the body of this if statement into a member function to avoid code duplication. Apply the same change to the other member functions of this struct. The newly extracted member functions should be inlined to make them fast.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted three shared inlined helpers on ClassicLruTryGetNode, TryRemoveNode, and TryUpdateValue — each marked with [MethodImpl(MethodImplOptions.AggressiveInlining)]. Both the public ClassicLru methods (TryGet, TryRemove, TryUpdate, AddOrUpdate) and the AlternateLookup struct now call these shared helpers. Commit: 0c52d6e

…ClassicLru and AlternateLookup

Agent-Logs-Url: https://github.com/bitfaster/BitFaster.Caching/sessions/e585fcf1-6b1d-4922-bc87-8b6fb552ce99

Co-authored-by: bitfaster <12851828+bitfaster@users.noreply.github.com>
Copilot AI requested a review from bitfaster March 30, 2026 18:43
@bitfaster bitfaster marked this pull request as ready for review March 30, 2026 20:52
@bitfaster bitfaster merged commit 44768fe into main Mar 30, 2026
16 checks passed
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