Skip to content

node-cache - fix: has was not removing expired keys#1618

Merged
jaredwray merged 3 commits intomainfrom
claude/fix-issue-1617-vVz6Q
Apr 15, 2026
Merged

node-cache - fix: has was not removing expired keys#1618
jaredwray merged 3 commits intomainfrom
claude/fix-issue-1617-vVz6Q

Conversation

@jaredwray
Copy link
Copy Markdown
Owner

has() previously returned true for expired keys, breaking the
has()/get() pattern used with the original node-cache. It now checks
the TTL, emits "expired", and removes the key (when deleteOnExpire is
enabled), matching node-cache's behavior.

has() previously returned true for expired keys, breaking the
has()/get() pattern used with the original node-cache. It now checks
the TTL, emits "expired", and removes the key (when deleteOnExpire is
enabled), matching node-cache's behavior.
@jaredwray jaredwray changed the title claude/fix-issue-1617-vVz6Q node-cache - fix: has was not removing expired keys Apr 15, 2026
@jaredwray
Copy link
Copy Markdown
Owner Author

#1617

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the has() method to correctly handle expired keys by returning false, emitting an 'expired' event, and optionally deleting the entry. This change aligns the behavior with the get() method and the original node-cache library. A review comment highlights a potential issue where repeated calls to has() on an expired key could cause event flooding if deleteOnExpire is set to false.

Comment thread packages/node-cache/src/index.ts Outdated
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1618   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines         2485      2492    +7     
  Branches       556       556           
=========================================
+ Hits          2485      2492    +7     

☔ View full report in Codecov by Sentry.
📢 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.

claude added 2 commits April 15, 2026 17:05
When deleteOnExpire is false, repeatedly accessing an expired key via
get()/has() (or hitting it via the checkData() interval sweep) would
emit the "expired" event on every call, flooding listeners. Centralize
the expiration path in a handleExpired() helper and track an
"expiredEmitted" flag on the entry so the event fires once. The flag
is reset when the entry is re-set or its ttl is re-scheduled.

mget()/take() go through get() and inherit this behavior.
Drop the expiredEmitted de-duplication. The "expired" event now fires
on every access to an expired entry (get/has/checkData), regardless of
the deleteOnExpire option. Callers that want one-shot semantics can
track that themselves.
@jaredwray jaredwray merged commit ac27d22 into main Apr 15, 2026
10 checks passed
@jaredwray jaredwray deleted the claude/fix-issue-1617-vVz6Q branch April 15, 2026 19:25
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.

2 participants