$request_time =
$request->server->
get('REQUEST_TIME'
);
// The response passes all of the above checks, so cache it. Page cache
// entries default to Cache::PERMANENT since they will be expired via cache
// tags locally. Because of this, page cache ignores max age.
// - Get the tags from CacheableResponseInterface per the earlier comments.
// - Get the time expiration from the Expires header, rather than the
// interface, but see https://www.drupal.org/node/2352009 about possibly
// changing that.
$expire = 0;
// 403 and 404 responses can fill non-LRU cache backends and generally are
// likely to have a low cache hit rate. So do not cache them permanently.
if ($response->
isClientError()) { // Cache for an hour by default. If the 'cache_ttl_4xx' setting is
// set to 0 then do not cache the response.
$cache_ttl_4xx = Settings::
get('cache_ttl_4xx', 3600
);
if ($cache_ttl_4xx > 0
) { $expire =
$request_time +
$cache_ttl_4xx;
} } // The getExpires method could return NULL if Expires header is not set, so
// the returned value needs to be checked before calling getTimestamp.
elseif ($expires =
$response->
getExpires()) { $date =
$expires->
getTimestamp();