Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Response.php

function Response::getMaxAge

Returns the number of seconds after the time specified in the response's Date header when the response should no longer be considered fresh.

First, it checks for a s-maxage directive, then a max-age directive, and then it falls back on an expires header. It returns null when no maximum age can be established.

@final

2 calls to Response::getMaxAge()
Response::expire in vendor/symfony/http-foundation/Response.php
Marks the response stale by setting the Age header to be equal to the maximum age of the response.
Response::getTtl in vendor/symfony/http-foundation/Response.php
Returns the response's time-to-live in seconds.

File

vendor/symfony/http-foundation/Response.php, line 758

Class

Response
Response represents an HTTP response.

Namespace

Symfony\Component\HttpFoundation

Code

public function getMaxAge() : ?int {
    if ($this->headers
        ->hasCacheControlDirective('s-maxage')) {
        return (int) $this->headers
            ->getCacheControlDirective('s-maxage');
    }
    if ($this->headers
        ->hasCacheControlDirective('max-age')) {
        return (int) $this->headers
            ->getCacheControlDirective('max-age');
    }
    if (null !== ($expires = $this->getExpires())) {
        $maxAge = (int) $expires->format('U') - (int) $this->getDate()
            ->format('U');
        return max($maxAge, 0);
    }
    return null;
}
RSS feed
Powered by Drupal