Skip to content

feat: add fireOnEvict option to cleanup() - #498

Merged
avoidwork merged 2 commits into
masterfrom
fix/keys-expired-filtering
Sep 27, 2026
Merged

avoidwork merged 2 commits into
masterfrom
fix/keys-expired-filtering

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

Description

Adds an optional fireOnEvict parameter to cleanup(). When true, it invokes the onEvict callback for each expired item removed. Defaults to false, preserving the existing silent behavior so no existing callers are affected. This gives users a way to purge stale items while still receiving eviction notifications for resource cleanup.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)
  • Performance improvement
  • CI / build / tooling

Testing

Added tests for both paths: cleanup(true) fires onEvict for each removed item, and cleanup() (default) does not. Ran npm test (172 tests, 27 suites, all passing). Coverage maintained at 100% lines / 99.40% branches / 100% functions.

Coverage

  • 100% line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with 100% line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

keys() now filters expired items, consistent with entries(), values(),
and toJSON(). Previously it returned every key regardless of expiry,
so iterating keys() then calling get(key) could yield undefined for
expired entries. Adds a regression test and corrects the getMany()
README line to match its tested behavior.
cleanup() now accepts an optional fireOnEvict parameter. When true, it
invokes the onEvict callback for each expired item removed. Defaults to
false, preserving the existing silent behavior so no existing callers
are affected. Adds tests for both paths and updates docs and types.
@avoidwork avoidwork self-assigned this Sep 27, 2026
@avoidwork
avoidwork merged commit da90b42 into master Sep 27, 2026
4 checks passed
@avoidwork
avoidwork deleted the fix/keys-expired-filtering branch September 27, 2026 02:52
@avoidwork avoidwork mentioned this pull request Sep 27, 2026
12 tasks
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.

1 participant