| 532 | return self.capacity + self.capacity * self.threshold |
| 533 | |
| 534 | def _manage_size(self) -> None: |
| 535 | if not self._mutex.acquire(False): |
| 536 | return |
| 537 | try: |
| 538 | size_alert = bool(self.size_alert) |
| 539 | while len(self) > self.capacity + self.capacity * self.threshold: |
| 540 | if size_alert: |
| 541 | size_alert = False |
| 542 | self.size_alert(self) # type: ignore |
| 543 | by_counter = sorted( |
| 544 | self._data.values(), |
| 545 | key=operator.itemgetter(2), |
| 546 | reverse=True, |
| 547 | ) |
| 548 | for item in by_counter[self.capacity :]: |
| 549 | try: |
| 550 | del self._data[item[0]] |
| 551 | except KeyError: |
| 552 | # deleted elsewhere; skip |
| 553 | continue |
| 554 | finally: |
| 555 | self._mutex.release() |
| 556 | |
| 557 | |
| 558 | class _CreateFuncType(Protocol[_T_co]): |