* Set the MaxEntries of the cache. If the maxEntries is decreased, reduce * entries in the cache.
(maxEntries: number)
| 61 | * entries in the cache. |
| 62 | */ |
| 63 | public setMaxEntries(maxEntries: number): void { |
| 64 | if (maxEntries < 0) { |
| 65 | throw new Error( |
| 66 | `The maxEntries of LRU caches must be at least 0, but got ${ |
| 67 | maxEntries}.`); |
| 68 | } |
| 69 | |
| 70 | if (this.maxEntries > maxEntries) { |
| 71 | for (let i = 0; i < this.maxEntries - maxEntries; i++) { |
| 72 | const keyToDelete = this.cache.keys().next().value; |
| 73 | this.cache.delete(keyToDelete); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | this.maxEntries = maxEntries; |
| 78 | } |
| 79 | } |
no test coverage detected