Esempio n. 1
0
 public function testDisableCache()
 {
     // disable cache
     $this->structure->getCacheLifeTime()->willReturn(0);
     $this->response->setPublic()->shouldNotBeCalled();
     $this->response->setMaxAge($this->maxAge)->shouldNotBeCalled();
     $this->response->setSharedMaxAge($this->sharedMaxAge)->shouldNotBeCalled();
     $this->handler->updateResponse($this->response->reveal(), $this->structure->reveal());
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     // when structure cache-lifetime disabled - return
     if ((int) $structure->getCacheLifeTime() === 0) {
         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() + intval($structure->getCacheLifeTime()) : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }