(self: Cache<K, A, E, R>)
| 489 | } |
| 490 | |
| 491 | const checkCapacity = <K, A, E, R>(self: Cache<K, A, E, R>) => { |
| 492 | let diff = MutableHashMap.size(self.map) - self.capacity |
| 493 | if (diff <= 0) return |
| 494 | // MutableHashMap has insertion order, so we can remove the oldest entries |
| 495 | for (const [key] of self.map) { |
| 496 | MutableHashMap.remove(self.map, key) |
| 497 | diff-- |
| 498 | if (diff === 0) return |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Reads an existing cache entry without invoking the lookup function. |