public function Response::getMaxAge

Same name in this branch

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.

@api

Return value

integer|null Number of seconds

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

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php, line 696

Class

Response
Response represents an HTTP response.

Namespace

Symfony\Component\HttpFoundation

Code

public function getMaxAge() {
  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 !== $this
    ->getExpires()) {
    return $this
      ->getExpires()
      ->format('U') - $this
      ->getDate()
      ->format('U');
  }
  return null;
}