fix: LRU edge cases in TTL handling and factory validation - #488
Merged
Merged
Conversation
- Validate max/ttl/resetTTL in constructor (reject non-integer, negative, non-boolean) - Reclaim expired keys on set()/setWithEvicted() instead of leaving dead slots - Skip expired items in values()/entries()/forEach()/toJSON() - Make forEach() mutation-safe (capture next pointer before callback) - Stop incrementing deletes when get() removes an expired item on a miss - Validate array input in getMany()/hasAll()/hasAny()/values()/entries() - Treat expiry=0 with ttl>0 as expired in sizeByTTL/keysByTTL/valuesByTTL - Use silent eviction in setWithEvicted() (no onEvict double-fire) Fixes #487
Owner
Author
Performance Audit — No RegressionRan the Results (pre-PR vs. PR)Improvements (the bulk):
Slight regressions (all within noise):
Why the regressions aren't realThe 5000-size cases report ±19% variance in the benchmark's own output. A +4% shift on a ±19% measurement is pure noise. The Code-level reasoning
Bottom line: The |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes 14 edge cases in TTL handling and factory validation for the LRU cache. Validates constructor inputs, reclaims expired keys on set(), skips expired items in read methods, makes forEach() mutation-safe, fixes get() stats, validates array inputs, corrects expiry=0 semantics, and silences setWithEvicted() eviction notification.
Type of Change
Testing
Added 19 new unit tests covering the edge cases: factory validation with non-integer/negative/boolean inputs, expired-key set() with both resetTTL values, read-method TTL enforcement, forEach() mutation safety, get() stats on expired, getMany()/has*() array validation, expiry=0 semantics, and setWithEvicted() silent eviction. Updated 3 existing tests for the corrected expiry=0 behavior.
Coverage
Checklist
npm run lintpasses