protected function ttlToTimestamp($ttl): ?int
    {
        if (!isset($ttl)) {
            return isset($this->ttl) ? time() + $this->ttl : null;
        }

        if (is_int($ttl)) {
            return time() + (isset($this->ttl) ? min($ttl, $this->ttl) : $ttl);
        }

        if ($ttl instanceof DateInterval) {
            $timestamp = (new DateTimeImmutable())->add($ttl)->getTimestamp();

            return isset($this->ttl) ? min($timestamp, time() + $this->ttl) : $timestamp;
        }

        $type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl);
        throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type");
    }