Skip to content

fix(node-cache): Fixing issues with metrics reporting#1650

Merged
jaredwray merged 3 commits into
jaredwray:mainfrom
jmjones88:main
Jun 4, 2026
Merged

fix(node-cache): Fixing issues with metrics reporting#1650
jaredwray merged 3 commits into
jaredwray:mainfrom
jmjones88:main

Conversation

@jmjones88
Copy link
Copy Markdown
Contributor

@jmjones88 jmjones88 commented Jun 2, 2026

Please check if the PR fulfills these requirements

  • Followed the Contributing guidelines and Code of Conduct
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
This fixes multiple metrics-accounting issues that caused inaccurate ksize and vsize reporting over time.

The changes ensure that:

  • Overwriting existing keys does not inflate size metrics.
  • take() correctly removes keys even when cached values are falsy.
  • NodeCacheStore correctly decrements value-size metrics for undefined values on overwrite, delete, and expiry.

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 optimizes the node-cache package by introducing an in-memory _values map in NodeCacheStore to track cached values synchronously, preventing redundant asynchronous lookups and fixing stats inflation during key overwrites. It also updates the take() method to support falsy values and adds comprehensive tests. The reviewer feedback highlights two critical issues: first, using this.store.has() in take() can incorrectly identify expired keys as existing, leading to premature deletion when deleteOnExpire is disabled; second, checking result !== undefined in the store's retrieval logic fails when a cached value is explicitly set to undefined, which can cause memory leaks. Code suggestions are provided to address both issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/node-cache/src/index.ts
Comment thread packages/node-cache/src/store.ts Outdated
jmjones88 and others added 2 commits June 2, 2026 12:51
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c6c3e21) to head (31cd096).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1650   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines         2688      2705   +17     
  Branches       595       598    +3     
=========================================
+ Hits          2688      2705   +17     

☔ 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.

@jaredwray jaredwray merged commit ee73e5a into jaredwray:main Jun 4, 2026
9 checks passed
@jaredwray
Copy link
Copy Markdown
Owner

@jmjones88 - thanks for the fix. We should have this live soon

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