protected function ttlToSeconds($ttl): ?int
    {
        if (!isset($ttl)) {
            return $this->ttl;
        }

        if ($ttl instanceof DateInterval) {
            $reference = new DateTimeImmutable();
            $endTime = $reference->add($ttl);

            $ttl = $endTime->getTimestamp() - $reference->getTimestamp();
        }

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

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