Repository navigation
node-cache - fix: keep falsy values in mget() and honor deleteOnExpire in TTL methods - #1762
Merged
jaredwray merged 2 commits intoNov 19, 2026
Merged
Conversation
…keys in ttl() and getTtl() mget() dropped 0, false, "" and null. ttl() gave an expired key a new ttl, and getTtl() returned the old timestamp of an expired key. Now both functions handle an expired key like get() and has(). Fixes #1761
Owner
|
@bardrop - thanks for the help on this. It should get released in the next couple weeks |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1762 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 29
Lines 3621 3632 +11
Branches 825 828 +3
=========================================
+ Hits 3621 3632 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
Bug fix. Fixes #1761.
What changed
mget()keeps0,false,"", andnull. It omits keys whenget()returnsundefined.ttl()andgetTtl()delete an expired key and emit oneexpiredevent. They returnfalseandundefined, respectively.deleteOnExpire: false, a caller can read the expiration time or renew a retained key. Anexpiredlistener can do both without a second event for the same entry.Verification
pnpm buildandnode scripts/test-build.mjspassed.pnpm testpassed on Node 24. All 1,397 tests passed, including 161 in@cacheable/node-cache.c587fd0and passed on875f464. The case for listener renewal also failed on the original PR commit,8f3af7c.Test audit
undefined.getTtl()andttl()with two cases in one table. Each case checks the return value, immediate deletion, and the event arguments. The oldttl()test let a laterget()delete the key.deleteOnExpire: false. The revised case checks the expiration time, renewal from a listener, and the number of events. The original assertion conflicted with the behavior for retained keys.ttl(). The renewal case cannot detect an update that restores a deleted entry.