Skip to content

Add support for WithEvents to ConcurrentLfuBuilder#797

Merged
bitfaster merged 10 commits into
mainfrom
users/alexpeck/lfubuilderevents
May 3, 2026
Merged

Add support for WithEvents to ConcurrentLfuBuilder#797
bitfaster merged 10 commits into
mainfrom
users/alexpeck/lfubuilderevents

Conversation

@bitfaster
Copy link
Copy Markdown
Owner

@bitfaster bitfaster commented May 1, 2026

  • Builder now supports WithEvents. Previously, ConcurrentLfu did not have events, so this preserves existing behavior for the builder.
  • Builder returns internal class FastConcurrentLfu which uses the NoEventsPolicy. It supports both access order and time based expiry via generic parameters. This means we can have a single class for both expiry modes. Since this is internal, user cannot see the ugly generics. We can later consider providing public FastConcurrentLfu and FastConcurrentTLfu and clean up the generics.
  • Implemented a test class base with derived test classes to verify basic functionality for access order, expire after access, expire after write and expire after policies.

Comment thread BitFaster.Caching.UnitTests/Lfu/ConcurrentLfuSoakTests.cs Outdated
@bitfaster
Copy link
Copy Markdown
Owner Author

@copilot fix the failing tests. Do not make any changes except for fixing the tests.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

@copilot fix the failing tests. Do not make any changes except for fixing the tests.

Fixed in de473ca. The root cause was that FastConcurrentLfu (the new default without events) didn't implement ITimePolicy/IDiscreteTimePolicy, so Policy.ExpireAfterWrite/ExpireAfterAccess/ExpireAfter.HasValue returned false. Added CreatePolicy() to properly detect the expiry policy type via typeof(P) check and implemented the time policy interface. Also updated TestScheduler to use WithEvents() since the default now returns FastConcurrentLfu instead of ConcurrentLfu.

@coveralls
Copy link
Copy Markdown

coveralls commented May 1, 2026

Coverage Status

coverage: 99.169%. first build — users/alexpeck/lfubuilderevents into main

@bitfaster bitfaster marked this pull request as ready for review May 2, 2026 02:42
@bitfaster bitfaster merged commit b202a24 into main May 3, 2026
18 checks passed
@bitfaster bitfaster deleted the users/alexpeck/lfubuilderevents branch May 3, 2026 04:00
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.

3 participants