public function Response::setCache

Sets the response's cache headers (validation and/or expiration).

Available options are: etag, last_modified, max_age, s_maxage, private, and public.

@api

Parameters

array $options An array of cache options:

Return value

Response

Throws

\InvalidArgumentException

File

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

Class

Response
Response represents an HTTP response.

Namespace

Symfony\Component\HttpFoundation

Code

public function setCache(array $options) {
  if ($diff = array_diff(array_keys($options), array(
    'etag',
    'last_modified',
    'max_age',
    's_maxage',
    'private',
    'public',
  ))) {
    throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
  }
  if (isset($options['etag'])) {
    $this
      ->setEtag($options['etag']);
  }
  if (isset($options['last_modified'])) {
    $this
      ->setLastModified($options['last_modified']);
  }
  if (isset($options['max_age'])) {
    $this
      ->setMaxAge($options['max_age']);
  }
  if (isset($options['s_maxage'])) {
    $this
      ->setSharedMaxAge($options['s_maxage']);
  }
  if (isset($options['public'])) {
    if ($options['public']) {
      $this
        ->setPublic();
    }
    else {
      $this
        ->setPrivate();
    }
  }
  if (isset($options['private'])) {
    if ($options['private']) {
      $this
        ->setPrivate();
    }
    else {
      $this
        ->setPublic();
    }
  }
  return $this;
}