setClientTtl() public method

This method adjusts the Cache-Control/max-age directive.
public setClientTtl ( integer $seconds ) : Response
$seconds integer Number of seconds
return Response
コード例 #1
0
 public function indexAction()
 {
     $response = new Response($this->dumper->dump(), 200, array('Content-Type' => 'application/xml'));
     $response->setPublic();
     $response->setClientTtl($this->httpCache['ttl']);
     return $response;
 }
コード例 #2
0
 /**
  * Return the response to the context hash request with a header containing
  * the generated hash.
  *
  * If the ttl is bigger than 0, cache headers will be set for this response.
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($event->getRequestType() != HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     if (!$this->requestMatcher->matches($event->getRequest())) {
         return;
     }
     $hash = $this->hashGenerator->generateHash();
     // status needs to be 200 as otherwise varnish will not cache the response.
     $response = new Response('', 200, array($this->hashHeader => $hash, 'Content-Type' => 'application/vnd.fos.user-context-hash'));
     if ($this->ttl > 0) {
         $response->setClientTtl($this->ttl);
         $response->setVary($this->userIdentifierHeaders);
         $response->setPublic();
     } else {
         $response->setClientTtl(0);
         $response->headers->addCacheControlDirective('no-cache');
     }
     $event->setResponse($response);
 }
コード例 #3
0
 public function testSetClientTtl()
 {
     $response = new Response();
     $response->setClientTtl(10);
     $this->assertEquals($response->getMaxAge(), $response->getAge() + 10);
 }
コード例 #4
0
ファイル: FrontController.php プロジェクト: gobjila/BackBee
 public function rssAction($uri = null)
 {
     if (null === $this->application) {
         throw new FrontControllerException('A valid BackBee application is required.', FrontControllerException::INTERNAL_ERROR);
     }
     if (false === $this->application->getContainer()->has('site')) {
         throw new FrontControllerException('A BackBee\\Site instance is required.', FrontControllerException::INTERNAL_ERROR);
     }
     $site = $this->application->getContainer()->get('site');
     if (false !== ($ext = strrpos($uri, '.'))) {
         $uri = substr($uri, 0, $ext);
     }
     if ('_root_' == $uri) {
         $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->getRoot($site);
     } else {
         $page = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page')->findOneBy(array('_site' => $site, '_url' => '/' . $uri, '_state' => Page::getUndeletedStates()));
     }
     try {
         $this->application->info(sprintf('Handling URL request `rss%s`.', $uri));
         $response = new Response($this->application->getRenderer()->render($page, 'rss', null, 'rss.phtml', false));
         $response->headers->set('Content-Type', 'text/xml');
         $response->setClientTtl(15);
         $response->setTtl(15);
         $this->send($response);
     } catch (\Exception $e) {
         $this->defaultAction('/rss/' . $uri);
     }
 }