public function StaticCache::setCache in Tome 8
Adds to the Tome cache.
@returns bool Whether or not adding to the cache was successful.
Parameters
\Symfony\Component\HttpFoundation\Request $request: A request object.
\Symfony\Component\HttpFoundation\Response $response: A response object that should be stored in the page cache.
string $original_path: The original, placeholdered path.
string $destination: The path to the saved static file.
Overrides StaticCacheInterface::setCache
File
- modules/
tome_static/ src/ StaticCache.php, line 100
Class
- StaticCache
- Determines if pages are statically cached.
Namespace
Drupal\tome_staticCode
public function setCache(Request $request, Response $response, $original_path, $destination) {
if (!$response instanceof CacheableResponseInterface) {
return FALSE;
}
$request_time = $request->server
->get('REQUEST_TIME');
if ($expires = $response
->getExpires()) {
$date = $expires
->getTimestamp();
$expire = $date > $request_time ? $date : Cache::PERMANENT;
}
else {
$expire = Cache::PERMANENT;
}
if ($expire === Cache::PERMANENT || $expire > $request_time) {
$tags = $response
->getCacheableMetadata()
->getCacheTags();
$cid = $this
->getCacheId($request
->getSchemeAndHttpHost(), $original_path);
$this
->set($cid, $destination, $expire, $tags);
if ($request
->getUri() !== $original_path) {
$cid = $this
->getCacheId($request
->getSchemeAndHttpHost(), $request
->getPathInfo());
$this
->set($cid, $destination, $expire, $tags);
}
}
return TRUE;
}