Skip to content

node-cache - fix: keep falsy values in mget() and honor deleteOnExpire in TTL methods - #1762

Merged
jaredwray merged 2 commits into
jaredwray:mainfrom
bardrop-oss:fix-node-cache-expired-ttl-mget
Nov 19, 2026
Merged

jaredwray merged 2 commits into
jaredwray:mainfrom
bardrop-oss:fix-node-cache-expired-ttl-mget

Conversation

@bardrop

@bardrop bardrop commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Please check if the PR fulfills these requirements

What kind of change does this PR introduce?

Bug fix. Fixes #1761.

What changed

  • mget() keeps 0, false, "", and null. It omits keys when get() returns undefined.
  • By default, ttl() and getTtl() delete an expired key and emit one expired event. They return false and undefined, respectively.
  • With deleteOnExpire: false, a caller can read the expiration time or renew a retained key. An expired listener can do both without a second event for the same entry.
  • A TTL operation uses the current entry after the listener returns. A listener can delete a retained key without the TTL operation creating it again.

Verification

  • pnpm build and node scripts/test-build.mjs passed.
  • pnpm test passed on Node 24. All 1,397 tests passed, including 161 in @cacheable/node-cache.
  • All five regression cases failed on c587fd0 and passed on 875f464. The case for listener renewal also failed on the original PR commit, 8f3af7c.
  • The test audit below covers each change to a test. All cases use the public API.

Test audit

  • Extended the falsy-value test to check that the result has no own property for an absent key. The old equality check accepted an extra property with the value undefined.
  • Replaced the separate default-expiry tests for getTtl() and ttl() with two cases in one table. Each case checks the return value, immediate deletion, and the event arguments. The old ttl() test let a later get() delete the key.
  • Replaced the test that rejected renewal with 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.
  • Added a case in which a listener deletes a retained key during ttl(). The renewal case cannot detect an update that restores a deleted entry.

bardrop and others added 2 commits November 18, 2026 01:13
…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
@jaredwray jaredwray changed the title node-cache - fix: keep falsy values in mget() and do not use expired keys in ttl() and getTtl() node-cache - fix: keep falsy values in mget() and honor deleteOnExpire in TTL methods Nov 18, 2026
@jaredwray
jaredwray merged commit d6b7d6f into jaredwray:main Nov 19, 2026
10 checks passed
@jaredwray

Copy link
Copy Markdown
Owner

@bardrop - thanks for the help on this. It should get released in the next couple weeks

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c587fd0) to head (875f464).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

node-cache: mget() drops falsy values, and ttl() / getTtl() use expired keys

2 participants