Skip to content

Commit f9fa146

Browse files
committed
fix(config-cache): has() no longer inflates hit/miss stats
has() delegated to get(), which increments this.hits or this.misses. The common has()+get() pattern double-counted every lookup. Re-implement has() with its own TTL check so cache statistics stay accurate. 35 unit tests added including 3 regression tests for this fix. Closes #497
1 parent e9711fa commit f9fa146

3 files changed

Lines changed: 424 additions & 102 deletions

File tree

.aios-core/core/config/config-cache.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,17 @@ class ConfigCache {
7272
* @returns {boolean} True if key exists and is valid
7373
*/
7474
has(key) {
75-
return this.get(key) !== null;
75+
// Check directly instead of delegating to get(), which would
76+
// increment hits/misses and inflate cache statistics (fixes #497)
77+
if (!this.cache.has(key)) return false;
78+
79+
const timestamp = this.timestamps.get(key);
80+
if (Date.now() - timestamp > this.ttl) {
81+
this.cache.delete(key);
82+
this.timestamps.delete(key);
83+
return false;
84+
}
85+
return true;
7686
}
7787

7888
/**

0 commit comments

Comments
 (0)