Add a new item, or reset the expiry time of an existing item.
(self, item, now=None)
| 530 | self._heap[:] = [] |
| 531 | |
| 532 | def add(self, item, now=None): |
| 533 | # type: (Any, float) -> None |
| 534 | """Add a new item, or reset the expiry time of an existing item.""" |
| 535 | now = now or time.monotonic() |
| 536 | if item in self._data: |
| 537 | self.discard(item) |
| 538 | entry = (now, item) |
| 539 | self._data[item] = entry |
| 540 | heappush(self._heap, entry) |
| 541 | if self.maxlen and len(self._data) >= self.maxlen: |
| 542 | self.purge() |
| 543 | |
| 544 | def update(self, other): |
| 545 | # type: (Iterable) -> None |