Sets the response's cache headers (validation and/or expiration).
Available options are: etag, last_modified, max_age, s_maxage, private, and public.
@api
array $options An array of cache options:
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;
}