Skip to content

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

Open
jmjones88 wants to merge 2 commits into
jaredwray:mainfrom
jmjones88:main
Open

fix(node-cache): Fixing issues with metrics reporting#1650
jmjones88 wants to merge 2 commits into
jaredwray:mainfrom
jmjones88:main

Conversation

@jmjones88
Copy link
Copy Markdown

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 MR 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
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

1 participant