Skip to content

Conversation

Copy link

Copilot AI commented Jan 5, 2026

Stats count was being incremented unconditionally after every set() operation, causing overcounting when updating existing keys.

Changes

  • set() method: Check if key exists via this._keyv.has() before incrementing count. Only new keys increment the counter.
  • mset() method: Apply same logic for batch operations - each item checks existence before count increment.
  • maxKeys enforcement: Updated to only reject new keys when at capacity. Updates to existing keys are allowed regardless of limit.

Example

const store = new NodeCacheStore({ maxKeys: 2, stats: true });

await store.set("key1", "value1");  // count = 1 ✓
await store.set("key2", "value2");  // count = 2 ✓
await store.set("key1", "updated");  // count = 2 (not 3) ✓
await store.set("key3", "value3");  // rejected (at limit) ✓

Tests added to verify count behavior for both single and batch operations.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jaredwray <1205481+jaredwray@users.noreply.github.com>
Copilot AI changed the title [WIP] Update node-cache implementation based on review feedback Fix stats count tracking to only increment for new keys, not updates Jan 5, 2026
Copilot AI requested a review from jaredwray January 5, 2026 22:06
Base automatically changed from node-cache---feat-(breaking)-moving-to-Keyv-as-the-storage to main January 5, 2026 22:27
@jaredwray jaredwray closed this Jan 6, 2026
@jaredwray jaredwray deleted the copilot/sub-pr-1524 branch January 9, 2026 19:48
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