Skip to content

Conversation

Copy link

Copilot AI commented Jan 5, 2026

The setTtl method performs a get operation to check if a key exists but doesn't track stats, leading to inconsistent hit/miss counts across the store.

Changes:

  • Added incrementHits() call when item exists
  • Added incrementMisses() call when item doesn't exist
  • Changed condition to item !== undefined for consistency with get() method
public async setTtl(key: string | number, ttl?: number | string): Promise<boolean> {
    const item = await this._keyv.get(key.toString());
    if (item !== undefined) {
        this._stats.incrementHits();  // Now tracked
        const finalTtl = this.resolveTtl(ttl);
        await this._keyv.set(key.toString(), item, finalTtl);
        return true;
    }
    
    this._stats.incrementMisses();  // Now tracked
    return false;
}

Stats tracking now consistent across all get operations in the store.


💡 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 PR to address feedback on moving to Keyv as storage Track stats in setTtl method for consistent hit/miss tracking Jan 5, 2026
Copilot AI requested a review from jaredwray January 5, 2026 22:22
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-yet-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