-
-
Notifications
You must be signed in to change notification settings - Fork 937
fix(config-cache): has() no longer inflates hit/miss statistics #498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,23 @@ class ConfigCache { | |
| * @returns {boolean} True if key exists and is valid | ||
| */ | ||
| has(key) { | ||
| return this.get(key) !== null; | ||
| // Check directly instead of delegating to get(), which would | ||
| // increment hits/misses and inflate cache statistics (fixes #497) | ||
| if (!this.cache.has(key)) return false; | ||
|
|
||
| // If timestamp is missing, maps are out-of-sync — treat as invalid | ||
| if (!this.timestamps.has(key)) { | ||
| this.cache.delete(key); | ||
| return false; | ||
| } | ||
|
|
||
| const timestamp = this.timestamps.get(key); | ||
| if (Date.now() - timestamp > this.ttl) { | ||
| this.cache.delete(key); | ||
| this.timestamps.delete(key); | ||
| return false; | ||
| } | ||
| return true; | ||
|
Comment on lines
+75
to
+91
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has()only checksthis.cache.has(key)but assumes a correspondingtimestampexists. If the maps ever become out-of-sync (e.g., timestamp missing),Date.now() - timestampbecomesNaNand the entry will be treated as non-expired, returningtrue. Consider treating a missing timestamp as invalid (cleanup +false) or checkingthis.timestamps.has(key)alongsidethis.cache.has(key).