本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setMaxAge方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setMaxAge方法的具体用法?PHP Response::setMaxAge怎么用?PHP Response::setMaxAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::setMaxAge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDisableCache
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());
}
示例2: indexAction
public function indexAction($campaignHash, $platformHash, $isNextButton)
{
if ($campaignHash === 'next') {
$campaign = null;
} else {
$campaignRepo = $this->em->getRepository('VifeedCampaignBundle:Campaign');
$campaign = $campaignRepo->findOneBy(['hashId' => $campaignHash]);
if (!$campaign) {
throw $this->createNotFoundException('The video is not found');
}
if (!$campaign->getUser()->isEnabled()) {
throw $this->createNotFoundException();
}
}
$platformRepo = $this->em->getRepository('VifeedPlatformBundle:Platform');
$platform = $platformRepo->findOneBy(['hashId' => $platformHash]);
if ($platform && !$platform->getUser()->isEnabled()) {
throw $this->createNotFoundException();
}
$videoHash = $campaign ? $campaign->getHash() : null;
$meta = $this->getMeta($campaign);
$meta['og:url'] = $this->get('router')->generate('vifeed_video_promo_homepage', ['platformHash' => $platformHash, 'campaignHash' => $campaignHash, 'domain' => $this->container->getParameter('promo_domain')]);
$response = new Response();
$response->setPublic();
$response->setMaxAge(60 * 60 * 3);
return $this->render('VifeedVideoPromoBundle:Default:index.html.twig', ['platformHash' => $platformHash, 'campaignHash' => $campaignHash, 'campaignTitle' => $campaign ? $campaign->getName() : null, 'campaignDescription' => $campaign ? $campaign->getDescription() : null, 'videoHash' => $videoHash, 'nextBtn' => $isNextButton, 'meta' => $meta], $response);
}
示例3: filter
/**
*
*
* @param Event $event An Event instance
*/
public function filter(Event $event, Response $response)
{
if (!$configuration = $event->get('request')->attributes->get('_cache')) {
return $response;
}
if (!$response->isSuccessful()) {
return $response;
}
if (null !== $configuration->getSMaxAge()) {
$response->setSharedMaxAge($configuration->getSMaxAge());
}
if (null !== $configuration->getMaxAge()) {
$response->setMaxAge($configuration->getMaxAge());
}
if (null !== $configuration->getExpires()) {
$date = \DateTime::create(\DateTime::createFromFormat('U', $configuration->getExpires(), new \DateTimeZone('UTC')));
$response->setLastModified($date);
}
return $response;
}
示例4: update
/**
* {@inheritdoc}
*/
public function update(Response $response)
{
// if we have no embedded Response, do nothing
if (0 === $this->embeddedResponses) {
return;
}
// Remove validation related headers in order to avoid browsers using
// their own cache, because some of the response content comes from
// at least one embedded response (which likely has a different caching strategy).
if ($response->isValidateable()) {
$response->setEtag(null);
$response->setLastModified(null);
$this->cacheable = false;
}
if (!$this->cacheable) {
$response->headers->set('Cache-Control', 'no-cache, must-revalidate');
return;
}
$this->ttls[] = $response->getTtl();
$this->maxAges[] = $response->getMaxAge();
if (null !== ($maxAge = min($this->maxAges))) {
$response->setSharedMaxAge($maxAge);
$response->headers->set('Age', $maxAge - min($this->ttls));
}
$response->setMaxAge(0);
}
示例5: apiIntroAction
function apiIntroAction()
{
$response = new Response();
$response->setPublic();
$response->setMaxAge($this->container->getParameter('cache_expiration'));
return $this->render('AppBundle:Default:apiIntro.html.twig', array("pagetitle" => "API", "game_name" => $this->container->getParameter('game_name'), "publisher_name" => $this->container->getParameter('publisher_name')), $response);
}
示例6: cacheResponse
/**
* Cache the response 1 year (31536000 sec)
*/
protected function cacheResponse(Response $response)
{
$response->setSharedMaxAge(31536000);
$response->setMaxAge(31536000);
$response->setExpires(new \DateTime('+1 year'));
return $response;
}
示例7: importAction
public function importAction()
{
$response = new Response();
$response->setPublic();
$response->setMaxAge($this->container->getParameter('long_cache'));
return $this->render('NetrunnerdbBuilderBundle:Builder:directimport.html.twig', array('pagetitle' => "Import a deck", 'locales' => $this->renderView('NetrunnerdbCardsBundle:Default:langs.html.twig')), $response);
}
示例8: handleResponse
/**
* Update a valid non cacheable Response with http cache headers
*
* @see http://symfony.com/fr/doc/current/book/http_cache.html
*/
public function handleResponse(Response $response)
{
// do not handle invalid response
if (!$response->isOk()) {
return $response;
}
// do not handle response with http cache headers
if ($response->isCacheable()) {
return $response;
}
// seek for optional configuration
$this->readRoutingConfiguration();
// mark the response as private
$response->setPrivate();
// set the private or shared max age
$response->setMaxAge($this->duration);
$response->setSharedMaxAge($this->duration);
// set expires
$date = new \DateTime();
$date->modify(sprintf('+%d seconds', $this->duration));
$response->setExpires($date);
// set a custom Cache-Control directive
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
示例9: getAction
/**
* Get the details of a person.
*
* @param int $id The ID of the person as assigned by MyAnimeList
*
* @return View
*/
public function getAction($id)
{
// http://myanimelist.net/people/#{id}
$downloader = $this->get('atarashii_api.communicator');
try {
$personDetails = $downloader->fetch('/people/' . $id);
} catch (Exception\CurlException $e) {
return $this->view(array('error' => 'network-error'), 500);
} catch (Exception\ClientErrorResponseException $e) {
$personDetails = $e->getResponse();
}
if (strpos($personDetails, 'This page doesn\'t exist') !== false) {
return $this->view(array('error' => 'not-found'), 200);
} else {
$person = PersonParser::parse($personDetails);
$response = new Response();
$response->setPublic();
$response->setMaxAge(86400);
//One day
$response->headers->addCacheControlDirective('must-revalidate', true);
//Also, set "expires" header for caches that don't understand Cache-Control
$date = new \DateTime();
$date->modify('+172800 seconds');
//two days
$response->setExpires($date);
$view = $this->view($person);
$view->setResponse($response);
$view->setStatusCode(200);
return $view;
}
}
示例10: apidocAction
function apidocAction()
{
$response = new Response();
$response->setPublic();
$response->setMaxAge($this->container->getParameter('cache_expiration'));
return $this->render('AppBundle:Default:apidoc.html.twig', array("pagetitle" => "API documentation"), $response);
}
示例11: getResponse
private function getResponse(Request $request, $name, array $files, $content_type)
{
if (!isset($files[$name])) {
return new Response('Not Found', 404, array('Content-Type' => 'text/plain'));
}
$file = $files[$name];
$response = new Response();
$response->setPublic();
$response->setMaxAge(self::EXPIRED_TIME);
$response->setSharedMaxAge(self::EXPIRED_TIME);
$response->headers->set('Content-Type', $content_type);
// set a custom Cache-Control directive
$response->headers->addCacheControlDirective('must-revalidate', true);
$date = new \DateTime();
$date->setTimestamp(strtotime($this->container->getParameter('sf.version')));
$response->setETag($date->getTimestamp());
$response->setLastModified($date);
if ($response->isNotModified($request)) {
return $response;
}
if (!file_exists($file)) {
throw new \Exception(sprintf("file `%s`, `%s` not exists", $name, $file));
}
$response->setContent(file_get_contents($file));
return $response;
}
示例12: setResponseMaxAge
/**
* Set response max age
*
* @param Response $response
* @param int $maxAge
*/
protected function setResponseMaxAge(Response $response, $maxAge)
{
if (-1 === $maxAge) {
$maxAge = 2629743;
}
$response->setMaxAge($maxAge);
}
示例13: fullTreeAction
/**
* @Route("/catalog/fulltree", name="spb_shop_catalog_fulltree")
*/
public function fullTreeAction()
{
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('SpbShopBundle:Category');
$controller = $this;
$options = array('decorate' => true, 'rootOpen' => '<ul class="dropdown-menu">', 'rootClose' => '</ul>', 'childOpen' => function ($child) {
if ($child['rgt'] - $child['lft'] == 1) {
return '<li>';
} else {
return '<li class="dropdown-submenu">';
}
}, 'childClose' => '</li>', 'nodeDecorator' => function ($node) use(&$controller) {
return '<a href="' . $controller->generateUrl('spb_shop_catalog_category', array('slug' => $node['slug'], 'tag' => $node['tag'])) . '">' . $node['title'] . '</a>';
});
$htmlTree = $repo->childrenHierarchy(null, false, $options);
$response = new Response($htmlTree);
// пометить ответ как public или private
$response->setPublic();
//$response->setPrivate();
//
// установить max age для private и shared ответов
$response->setMaxAge(6000);
$response->setSharedMaxAge(6000);
// установить специальную директиву Cache-Control
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
示例14: feedAction
/**
* @Route("/feed")
*/
public function feedAction()
{
$em = $this->getDoctrine()->getManager();
$manager = $this->getDoctrine()->getManager();
$core = $this->getParameter('core');
$dql = "SELECT p, pTrans FROM BlogBundle:Post p JOIN p.translations pTrans ORDER BY p.created DESC";
$entities = $manager->createQuery($dql)->getResult();
$rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
$rssfeed .= '<title>Kundalini Woman RSS feed</title>';
$rssfeed .= '<link>http://www.undaliniwoman.com</link>';
$rssfeed .= '<description>This is an example Kundalini Woman RSS feed</description>';
$rssfeed .= '<language>en-us</language>';
$rssfeed .= '<copyright>Copyright (C) 2009 mywebsite.com</copyright>';
foreach ($entities as $value) {
$rssfeed .= '<item>';
$rssfeed .= '<title>' . utf8_decode($value->getTitle()) . '</title>';
$rssfeed .= '<description>' . utf8_decode($value->getDescription()) . '</description>';
$rssfeed .= '<link>' . $core['server_base_url'] . $this->generateUrl('blog_blog_show', array('slug' => $value->getSlug())) . '</link>';
$rssfeed .= '<pubDate>' . $value->getCreated()->format("D, d M Y H:i:s O") . '</pubDate>';
$rssfeed .= '</item>';
}
$rssfeed .= '</channel>';
$rssfeed .= '</rss>';
$response = new Response($rssfeed);
$response->headers->set('Content-Type', 'application/rss+xml');
$response->setPublic();
$response->setMaxAge(3600);
$now = new DateTime();
$response->setLastModified($now);
return $response;
}
示例15: indexAction
public function indexAction()
{
$response = new Response();
$response->setMaxAge(60);
$response->setStatusCode(Response::HTTP_OK);
return $response;
}