Skip to content

Commit b52adfd

Browse files
committed
🐛 Fix potential double-eviction when updating an existing key (#1995)
1 parent a820479 commit b52adfd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/clients/cache.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,18 @@ export class Cache<T> {
9191
* @returns True if the key exists in the cache, false otherwise.
9292
*/
9393
has(key: string): boolean {
94-
return this.cache.has(key);
94+
const entry = this.cache.get(key);
95+
96+
if (!entry) {
97+
return false;
98+
}
99+
100+
if (Date.now() - entry.timestamp > this.timeToLive) {
101+
this.cache.delete(key);
102+
return false;
103+
}
104+
105+
return true;
95106
}
96107

97108
/**

0 commit comments

Comments
 (0)