Skip to content

Keep pending LFU entries eligible for callback eviction - #77

Merged
dgilland merged 1 commit into
dgilland:masterfrom
Aschenbath:fix/oss-20-20261125-77d1-cacheout-lfu-reentrant-eviction
Nov 25, 2026
Merged

dgilland merged 1 commit into
dgilland:masterfrom
Aschenbath:fix/oss-20-20261125-77d1-cacheout-lfu-reentrant-eviction

Conversation

@Aschenbath

Copy link
Copy Markdown
Contributor

LFU access counters are recorded after on_set returns. If that callback inserts another key into a cache with maxsize=1, eviction sees no candidates and the cache grows to two entries. With an existing hot entry, the same gap can evict the hot entry instead; popitem() from the callback can also incorrectly report an empty cache.

Include live entries that do not yet have an access counter when choosing an LFU victim. Such entries remain eligible while the outer insertion is still running, including insertion through add() and a callable get() default.

Validation on Windows:

  • All 9 new regression cases fail on unchanged master and pass with the fix.
  • Full suite: 426 tests pass with 100% coverage on Python 3.10, 3.11, 3.12, 3.13, and 3.14.
  • Ruff lint/format, mypy, package build, and Sphinx with warnings treated as errors pass.

Prepared with AI assistance and verified with the checks above.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — Aschenbath:fix/oss-20-20261125-77d1-cacheout-lfu-reentrant-eviction into dgilland:master

@dgilland
dgilland merged commit cf7249b into dgilland:master Nov 25, 2026
12 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.

3 participants