Stores the current page in the cache.
If page_compression is enabled, a gzipped version of the page is stored in the cache to avoid compressing the output on each request. The cache entry is unzipped in the relatively rare event that the page is requested by a client without gzip support.
Page compression requires the PHP zlib extension (http://php.net/manual/ref.zlib.php).
$body: The response body.
The cached object or NULL if the page cache was not set.
function drupal_page_set_cache(Response $response, Request $request) {
global $base_root;
if (drupal_page_is_cacheable()) {
$cache = (object) array(
'cid' => $base_root . $request
->getRequestUri(),
'data' => array(
'path' => $request->attributes
->get('system_path'),
'body' => $response
->getContent(),
'title' => drupal_get_title(),
'headers' => array(),
),
'tags' => array(
'content' => TRUE,
),
'expire' => CacheBackendInterface::CACHE_PERMANENT,
'created' => REQUEST_TIME,
);
$cache->data['headers'] = $response->headers
->all();
// Hack: exclude the x-drupal-cache header; it may make it in here because
// of awkwardness in how we defer sending it over in _drupal_page_get_cache.
if (isset($cache->data['headers']['x-drupal-cache'])) {
unset($cache->data['headers']['x-drupal-cache']);
}
// Use the actual timestamp from an Expires header, if available.
if ($date = $response
->getExpires()) {
$date = new DrupalDateTime($date);
$cache->expire = $date
->getTimestamp();
}
if ($cache->data['body']) {
if (config('system.performance')
->get('response.gzip') && extension_loaded('zlib')) {
$cache->data['body'] = gzencode($cache->data['body'], 9, FORCE_GZIP);
}
cache('page')
->set($cache->cid, $cache->data, $cache->expire, $cache->tags);
}
return $cache;
}
}