def METHOD_NAME(self) -> None:
    """Removes expired elements from the cache."""
    if self.soft_limit and len(self) <= self.soft_limit:
        return
    if self.hard_limit:
        while len(self) > self.hard_limit:
            self._expire_first()
    timestamp = time.monotonic()
    while True:
        key, item = self._first_item()
        if item.is_expired(timestamp):
            self._expire_first()
        else:
            break