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);
    }
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);
    }
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 ) ; }
Sets the expiry time.

@since 1.0.0

@param \DateTimeImmutable|null $expiry The expiry time or null for immediate expiry.
Sets the expiry time .