* A statement still being parsed cannot be closed yet: its `Parse` may not * have reached the socket. Let the cache exceed its bound temporarily, then * discard abandoned entries and close excess ready statements on access.
(protectedStatement?: Prepared)
| 1514 | * discard abandoned entries and close excess ready statements on access. |
| 1515 | */ |
| 1516 | private trim(protectedStatement?: Prepared): void { |
| 1517 | while (this.statements.size > this.max) { |
| 1518 | let evicted: Prepared | undefined |
| 1519 | for (const prepared of this.statements.values()) { |
| 1520 | if (prepared !== protectedStatement && (prepared.ready || !prepared.parsing)) { |
| 1521 | evicted = prepared |
| 1522 | break |
| 1523 | } |
| 1524 | } |
| 1525 | if (evicted === undefined) return |
| 1526 | this.statements.delete(evicted.key) |
| 1527 | if (evicted.ready) this.close(evicted.name) |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * Drops a statement the backend no longer holds, or whose plan went stale. |