Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     $response->headers->set(self::HEADER_HANDLERS, implode(', ', $this->handlerNames));
     $response->headers->set(self::HEADER_CLIENT_NAME, $this->proxyClientName);
     $response->headers->set(self::HEADER_STRUCTURE_TYPE, get_class($structure));
     $response->headers->set(self::HEADER_STRUCTURE_UUID, $structure->getUuid());
     // Structures implementing PageInterface have a TTL
     if ($structure instanceof PageInterface) {
         $cacheLifetimeData = $structure->getCacheLifeTime();
         $cacheLifeTime = $this->cacheLifetimeResolver->resolve($cacheLifetimeData['type'], $cacheLifetimeData['value']);
         $response->headers->set(self::HEADER_STRUCTURE_TTL, $cacheLifeTime);
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     $cacheLifetimeData = $structure->getCacheLifeTime();
     $cacheLifetime = $this->cacheLifetimeResolver->resolve($cacheLifetimeData['type'], $cacheLifetimeData['value']);
     // when structure cache-lifetime disabled - return
     if (0 === $cacheLifetime) {
         return;
     }
     // mark the response as either public or private
     $response->setPublic();
     // set the private and shared max age
     $response->setMaxAge($this->maxAge);
     $response->setSharedMaxAge($this->sharedMaxAge);
     $proxyTtl = $this->usePageTtl ? $response->getAge() + $cacheLifetime : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }
Beispiel #3
0
 /**
  * Load cache lifetime metadata.
  *
  * @param $path
  * @param \DOMXPath $xpath
  *
  * @return array
  */
 private function loadCacheLifetime($path, \DOMXPath $xpath)
 {
     $nodeList = $xpath->query($path);
     if (!$nodeList->length) {
         return ['type' => CacheLifetimeResolverInterface::TYPE_SECONDS, 'value' => 0];
     }
     // get first node
     $node = $nodeList->item(0);
     $type = $node->getAttribute('type');
     if ('' === $type) {
         $type = CacheLifetimeResolverInterface::TYPE_SECONDS;
     }
     $value = $node->nodeValue;
     if (!$this->cacheLifetimeResolver->supports($type, $value)) {
         throw new \InvalidArgumentException(sprintf('CacheLifetime "%s" with type "%s" not supported.', $value, $type));
     }
     return ['type' => $type, 'value' => $value];
 }