Skip to content

Conversation

Copy link

Copilot AI commented Jan 5, 2026

Both set and mset methods unconditionally incremented the stats count, causing overcount when updating existing keys instead of only tracking unique keys.

Changes

  • set method: Check key existence via keyv.has() before incrementing count; only increment for new keys
  • mset method: Check each key's existence before incrementing count
  • maxKeys enforcement: Allow updates to existing keys when at limit, only block new key additions
  • Type consistency: Fix setTtl to accept number | string TTL like other methods

Example

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

// Add 2 keys - count is 2
await store.set("key1", "value1");
await store.set("key2", "value2");

// Update existing keys - count remains 2 (previously would become 4)
await store.mset([
  { key: "key1", value: "updated1" },
  { key: "key2", value: "updated2" },
]);

// New key rejected at limit
await store.set("key3", "value3");  // Returns false, count still 2

The has() check adds one async operation per set but is necessary since Keyv's set doesn't distinguish inserts from updates.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 5, 2026 22:03
Co-authored-by: jaredwray <1205481+jaredwray@users.noreply.github.com>
Co-authored-by: jaredwray <1205481+jaredwray@users.noreply.github.com>
Copilot AI changed the title [WIP] Update storage implementation to use Keyv in node-cache Fix stats count overcount on key updates in NodeCacheStore Jan 5, 2026
Copilot AI requested a review from jaredwray January 5, 2026 22:08
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-again 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