Skip to content

Conversation

Copy link

Copilot AI commented Jan 5, 2026

The maxKeys check in NodeCacheStore.set() incorrectly rejected all operations when at capacity, preventing updates to existing keys. This breaks the expected behavior where maxKeys should only limit the number of distinct keys, not prevent modifications.

Changes

  • set() method: Check key existence before enforcing maxKeys limit. Only reject new keys when at capacity; allow updates to existing keys.
  • mset() method: Delegate to set() to respect maxKeys enforcement.
  • mget() method: Track hits/misses for statistics consistency with get().
  • take() method: Fix Stats API calls (recordHit/recordMissincrementHits/incrementMisses).
  • Count tracking: Only increment count for new keys, not updates (regardless of maxKeys setting).

Example

const store = new NodeCacheStore({ maxKeys: 3 });
await store.set("key1", "value1");
await store.set("key2", "value2");
await store.set("key3", "value3");

// Before: rejected (incorrect)
// After: succeeds (correct)
await store.set("key1", "updated");

// Both before and after: rejected (correct)
await store.set("key4", "value4"); // returns false

Test Coverage

Added test case verifying:

  • New keys rejected at maxKeys limit
  • Existing keys can be updated at maxKeys limit

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

Copilot AI self-assigned this Jan 5, 2026
Copilot AI and others added 4 commits January 5, 2026 22:21
Co-authored-by: jaredwray <1205481+jaredwray@users.noreply.github.com>
Co-authored-by: jaredwray <1205481+jaredwray@users.noreply.github.com>
Co-authored-by: jaredwray <1205481+jaredwray@users.noreply.github.com>
Co-authored-by: jaredwray <1205481+jaredwray@users.noreply.github.com>
Base automatically changed from node-cache---feat-(breaking)-moving-to-Keyv-as-the-storage to main January 5, 2026 22:27
Copilot AI and others added 2 commits January 5, 2026 22:28
…bility

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 Keyv based on feedback Fix maxKeys enforcement to allow updates to existing keys Jan 5, 2026
Copilot AI requested a review from jaredwray January 5, 2026 22:32
@jaredwray jaredwray closed this Jan 6, 2026
@jaredwray jaredwray deleted the copilot/sub-pr-1524-please-work 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