當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::setMaxAge方法代碼示例

本文整理匯總了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());
 }
開發者ID:ollietb,項目名稱:sulu,代碼行數:9,代碼來源:PublicHandlerTest.php

示例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);
 }
開發者ID:bzis,項目名稱:zomba,代碼行數:27,代碼來源:DefaultController.php

示例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;
    }
開發者ID:ruudk,項目名稱:FrameworkExtraBundle,代碼行數:31,代碼來源:AnnotationCacheListener.php

示例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);
 }
開發者ID:BusinessCookies,項目名稱:CoffeeMachineProject,代碼行數:29,代碼來源:ResponseCacheStrategy.php

示例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);
 }
開發者ID:ScotSalmon,項目名稱:thronesdb,代碼行數:7,代碼來源:DefaultController.php

示例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;
 }
開發者ID:Vrian7ipx,項目名稱:repocas,代碼行數:10,代碼來源:AssetController.php

示例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);
 }
開發者ID:adamcieslicki,項目名稱:netrunnerdb,代碼行數:7,代碼來源:BuilderController.php

示例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;
 }
開發者ID:kmelia,項目名稱:fresh-symfony,代碼行數:30,代碼來源:HttpCacheResponseHandler.php

示例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;
     }
 }
開發者ID:AnimeNeko,項目名稱:atarashii-mal-api,代碼行數:38,代碼來源:PersonController.php

示例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);
 }
開發者ID:ROMzombie,項目名稱:maginationduel-api,代碼行數:7,代碼來源:DefaultController.php

示例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;
 }
開發者ID:symforce,項目名稱:symforce-admin,代碼行數:26,代碼來源:IeController.php

示例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);
 }
開發者ID:itkg-canne,項目名稱:open-orchestra-display-bundle,代碼行數:13,代碼來源:CacheableManager.php

示例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;
 }
開發者ID:binidini,項目名稱:viktis,代碼行數:30,代碼來源:CatalogController.php

示例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;
 }
開發者ID:sebardo,項目名稱:blog,代碼行數:36,代碼來源:BlogController.php

示例15: indexAction

 public function indexAction()
 {
     $response = new Response();
     $response->setMaxAge(60);
     $response->setStatusCode(Response::HTTP_OK);
     return $response;
 }
開發者ID:seclu,項目名稱:playground,代碼行數:7,代碼來源:GameController.php


注:本文中的Symfony\Component\HttpFoundation\Response::setMaxAge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。