本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setClientTtl方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setClientTtl方法的具体用法?PHP Response::setClientTtl怎么用?PHP Response::setClientTtl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::setClientTtl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
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: onKernelRequest
/**
* 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: testSetClientTtl
public function testSetClientTtl()
{
$response = new Response();
$response->setClientTtl(10);
$this->assertEquals($response->getMaxAge(), $response->getAge() + 10);
}
示例4: rssAction
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);
}
}