public function SurrogateKeyGenerator::onRespond in Fastly 8.3
Logs an emergency event when the X-Drupal-Cache-Tags header exceeds 16 KB.
Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The event to process.
File
- src/
EventSubscriber/ SurrogateKeyGenerator.php, line 52
Class
- SurrogateKeyGenerator
- Generates a 'Surrogate-Key' header in the format expected by Fastly.
Namespace
Drupal\fastly\EventSubscriberCode
public function onRespond(FilterResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
$response = $event
->getResponse();
if (method_exists($response, 'getCacheableMetadata')) {
$surrogate_key_header_value = implode(' ', $response
->getCacheableMetadata()
->getCacheTags());
$cache_tags = explode(' ', $surrogate_key_header_value);
$hashes = $this->cacheTagsHash
->cacheTagsToHashes($cache_tags);
$siteId = $this->cacheTagsHash
->getSiteId();
$siteIdHash = $this->cacheTagsHash
->hashInput($siteId);
$hashes[] = $siteIdHash;
$surrogate_key_header_value = implode(' ', $hashes);
$response->headers
->set('Surrogate-Key', $surrogate_key_header_value);
}
}