Set the exact moment when the cache should expire.
@param DateTimeInterface $dt When the cache should expire
@return CachePolicy Provides fluent interface
161546
public function setExpireDate(DateTimeInterface $dt)
    {
        $this->expire_time = (int)$dt->format('U') - time();
        return $this;
    }
214117
public function min(Date $dt = null)
    {
        $dt = $dt ?: static::now($this->getTimezone());

        return $this->isBefore($dt) ? clone $this : clone $dt;
    }
923031
private function expirationToDateTime($expires): DateTimeInterface
    {
        if ($expires instanceof DateTimeImmutable) {
            return $expires;
        }

        if ($expires instanceof DateInterval) {
            $expires = (new DateTime)->add($expires);
        } elseif (is_string($expires) || is_int($expires)) {
            $expires = new DateTime(is_numeric($expires) ? '@' . $expires : $expires);
        }

        if (!$expires instanceof DateTimeInterface) {
            throw new InvalidArgumentException(
                'Invalid cookie expiration time. Cannot be converted to DateTimeInterface.'
            );
        }

        return new DateTimeImmutable($expires->format(DateTime::ISO8601), $expires->getTimezone());
    }
204556
public function expireCookie(ResponseInterface $response, $name)
    {
        $cookie = SetCookie::createExpired($name)
            ->withMaxAge($this->configuration['maxAge'])
            ->withPath($this->configuration['path'])
            ->withDomain($this->configuration['domain'])
            ->withSecure($this->configuration['secure'])
            ->withHttpOnly($this->configuration['httpOnly']);

        return $response->withAddedHeader(static::RESPONSE_COOKIE_NAME, $cookie);
    }
774416
public function setCache($useCache, $tableTTL, \Slab\Components\Cache\DriverInterface $cacheObject)
    {
        $this->cacheInterface = $cacheObject;
        $this->cacheTTL = $tableTTL;
        $this->enableCache = $useCache;

        return $this;
    }
922094
public function setExpiration(int $timestamp): self
    {
        if (!$this->validate->expiration($timestamp)) {
            throw new ValidateException('Expiration claim has expired.', 4);
        }

        $this->payload['exp'] = $timestamp;

        return $this;
    }
372851
public function withExpires(DateTime $date)
    {
        $timezone = new DateTimeZone("PRC");

        $this->withoutHeader('Expires');
        $date->setTimezone($timezone);
        $this->withHeader('Expires', $date->format('D, d M Y H:i:s') . ' GMT');

        $maxAge = $date->getTimestamp() - (new DateTime('now', $timezone))->getTimestamp();
        $this->withMaxAge($maxAge);

        return $this;
    }
202544
public function min(DateTime $dt = null)
    {
        $dt = $dt ?: static::now($this->timezone());

        return $this->lt($dt) ? $this : $dt;
    }
831989
private function isExpired(CacheItemInterface $item, DateTime $time = null)
    {
        $time = $time ?: new DateTime();
        return ($time > $item->getExpiresAt());
    }
547489
public function setExpiry(?\DateTimeImmutable $expiry = null): void
    {
        $date = new \DateTimeImmutable();
        $expiry = $expiry ?: $date;

        $this->setHeader('Date', $date->setTimezone(new \DateTimeZone('UTC'))->format('D, d M Y H:i:s \G\M\T'));
        $this->setHeader('Expires', $expiry->setTimezone(new \DateTimeZone('UTC'))->format('D, d M Y H:i:s \G\M\T'));

        if ($expiry <= $date) {
            $this->setHeader('Cache-Control', 'no-cache, no-store, must-revalidate, max-age=0');

            return;
        }

        $maxAge = $expiry->getTimestamp() - $date->getTimestamp();
        $this->setHeader('Cache-Control', 'public, max-age=' . $maxAge);
    }
609663
public function setExpires($period)
    {
        if (is_int($period))
            return $this->setExpiresInSeconds($period);
        if ($period instanceof DateTimeInterface)
            return $this->setExpireDate($period);
        if ($period instanceof DateInterval)
            return $this->setExpiresIn($period);

        throw new \InvalidArgumentException("A DateTime, DateInterval or int number of seconds is required");
    }
393976
public function setCoreCacheDbExpires($value)
    {
        $this->setFieldName('cache_db_expires');
        $this->loadObject(true);
        $this->setFieldValue($value);

        return $this;
    }
844973
public function isExpired(DateTime $dateTime)
    {
        if (null === $this->getExpiresIn()) {
            // if no expiry was indicated, assume it is valid
            return false;
        }

        // check to see if issuedAt + expiresIn > provided DateTime
        $expiresAt = clone $this->issuedAt;
        $expiresAt->add(new DateInterval(\sprintf('PT%dS', $this->getExpiresIn())));

        return $dateTime >= $expiresAt;
    }
54188
private function toDateTimeImmutable(?DateTimeInterface $value): ?DateTimeImmutable
    {
        if (true === $value instanceof DateTime) {
            $value = DateTimeImmutable::createFromMutable($value);
        }

        return $value;
    }
1287163
public static function tokensExpireIn(DateTimeInterface $date = null)
    {
        if (is_null($date)) {
            return static::$tokensExpireAt
                            ? Carbon::now()->diff(static::$tokensExpireAt)
                            : new DateInterval('P1Y');
        }

        static::$tokensExpireAt = $date;

        return new static;
    }
746380
public function expiresAfter($timeInterval)
    {
        if ($timeInterval instanceof DateInterval) {
            $this->expire = (int) DateTime::createFromFormat('U', time())->add($timeInterval)->format('U');
        } elseif (is_numeric($timeInterval)) {
            $this->expire = $timeInterval + time();
        } else {
            throw new InvalidArgumentException('not support datetime');
        }

        return $this;
    }
923599
public function setCache(?CacheInterface $cache)
    {
        if (!$cache) {
            $cache = new VoidCachePool();
        }
        $this->cache = $cache;

        return $this;
    }