Skip to content

Commit 31d46f2

Browse files
committed
fix: VipCache.has() now checks TTL expiry to match get() behavior
Previously has() returned true for expired entries since it only checked map.has(). Now checks expiresAt and cleans up expired entries with refCount=0, consistent with get() and acquire().
1 parent 8878092 commit 31d46f2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/vip-cache.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ export class VipCache<K, V> {
101101
}
102102

103103
has(key: K): boolean {
104-
return this.map.has(key);
104+
const entry = this.map.get(key);
105+
if (!entry) return false;
106+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
107+
if (entry.refCount === 0) this.map.delete(key);
108+
return false;
109+
}
110+
return true;
105111
}
106112

107113
/** Return the access count for a key without incrementing it. Returns 0 if not present. */

0 commit comments

Comments
 (0)