refactor: fix

This commit is contained in:
手瓜一十雪
2024-11-14 11:24:00 +08:00
parent 8f5baa47ec
commit 6b377416da
7 changed files with 54 additions and 48 deletions

View File

@@ -30,4 +30,13 @@ export class LRUCache<K, V> {
}
this.cache.set(key, value);
}
public resetCapacity(newCapacity: number): void {
this.capacity = newCapacity;
while (this.cache.size > this.capacity) {
const firstKey = this.cache.keys().next().value;
if (firstKey !== undefined) {
this.cache.delete(firstKey);
}
}
}
}