当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setSharedMaxAge方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setSharedMaxAge方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setSharedMaxAge方法的具体用法?PHP Response::setSharedMaxAge怎么用?PHP Response::setSharedMaxAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Response的用法示例。


在下文中一共展示了Response::setSharedMaxAge方法的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: 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

示例3: packagesAction

 /**
  * @Template()
  * @Route("/packages.json", name="packages", defaults={"_format" = "json"})
  */
 public function packagesAction(Request $req)
 {
     // fallback if any of the dumped files exist
     $rootJson = $this->container->getParameter('kernel.root_dir') . '/../web/packages_root.json';
     if (file_exists($rootJson)) {
         return new Response(file_get_contents($rootJson));
     }
     $rootJson = $this->container->getParameter('kernel.root_dir') . '/../web/packages.json';
     if (file_exists($rootJson)) {
         return new Response(file_get_contents($rootJson));
     }
     if ($req->getHost() === 'packagist.org') {
         $this->get('logger')->alert('packages.json is missing and the fallback controller is being hit');
         return new Response('Horrible misconfiguration or the dumper script messed up', 404);
     }
     $em = $this->get('doctrine')->getManager();
     gc_enable();
     $packages = $em->getRepository('Packagist\\WebBundle\\Entity\\Package')->getFullPackages();
     $notifyUrl = $this->generateUrl('track_download', array('name' => 'VND/PKG'));
     $data = array('notify' => str_replace('VND/PKG', '%package%', $notifyUrl), 'packages' => array());
     foreach ($packages as $package) {
         $versions = array();
         foreach ($package->getVersions() as $version) {
             $versions[$version->getVersion()] = $version->toArray();
             $em->detach($version);
         }
         $data['packages'][$package->getName()] = $versions;
         $em->detach($package);
     }
     unset($versions, $package, $packages);
     $response = new Response(json_encode($data), 200);
     $response->setSharedMaxAge(120);
     return $response;
 }
开发者ID:enriquesomolinos,项目名称:packagist,代码行数:38,代码来源:ApiController.php

示例4: userLinksAction

 /**
  * Renders page header links with cache control.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function userLinksAction()
 {
     $response = new Response();
     $response->setSharedMaxAge(3600);
     $response->setVary('Cookie');
     return $this->render('eZDemoBundle::page_header_links.html.twig', array(), $response);
 }
开发者ID:ezsystems,项目名称:demobundle,代码行数:12,代码来源:DemoController.php

示例5: sitemapAction

 public function sitemapAction()
 {
     $ttl = 3600 * 6;
     $response = new Response();
     $response->headers->set('Content-Type', 'text/xml');
     $response->setPublic();
     $response->setSharedMaxAge($ttl);
     $siteaccessName = $this->container->get('ezpublish.siteaccess')->name;
     $cacheFile = $this->container->getParameter('kernel.cache_dir') . '/sitemap_' . $siteaccessName . '.xml';
     $cacheFileMtime = 0;
     if (file_exists($cacheFile)) {
         $cacheFileMtime = stat($cacheFile)['mtime'];
     }
     if ($cacheFileMtime < time() - $ttl) {
         $urls = array();
         $hostname = $this->getRequest()->getHost();
         $publishToolsService = $this->get('cjw_publishtools.service.functions');
         $rootLocationId = $this->getConfigResolver()->getParameter('content.tree_root.location_id');
         $listLocations = $publishToolsService->fetchLocationListArr(array($rootLocationId), array('depth' => 10, 'limit' => 25000, 'main_location_only' => true, 'datamap' => false));
         foreach ($listLocations[$rootLocationId]['children'] as $location) {
             $loc = $this->generateUrl($location);
             $lastmod = date('c', $location->contentInfo->modificationDate->getTimestamp());
             $urls[] = array('loc' => $loc, 'lastmod' => $lastmod);
         }
         $sitemapXmlResponse = $this->render('CjwPublishToolsBundle::sitemap.xml.twig', array('urls' => $urls, 'hostname' => 'https://' . $hostname), $response);
         file_put_contents($cacheFile, $sitemapXmlResponse->getContent());
     } else {
         $sitemapXmlResponse = $response->setContent(file_get_contents($cacheFile));
     }
     return $sitemapXmlResponse;
 }
开发者ID:intermundiasolutions,项目名称:CjwPublishToolsBundle,代码行数:31,代码来源:SitemapsController.php

示例6: listBlogPostsAction

 /**
  * Displays the list of blog_post
  * Note: This is a fully customized controller action, it will generate the response and call
  *       the view. Since it is not calling the ViewControler we don't need to match a specific
  *       method signature.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location containing blog posts
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function listBlogPostsAction(Location $location, Request $request)
 {
     $response = new Response();
     // Setting default cache configuration (you can override it in you siteaccess config)
     $response->setSharedMaxAge($this->getConfigResolver()->getParameter('content.default_ttl'));
     // Make the response location cache aware for the reverse proxy
     $response->headers->set('X-Location-Id', $location->id);
     $response->setVary('X-User-Hash');
     $viewParameters = $request->attributes->get('viewParameters');
     // Getting location and content from ezpublish dedicated services
     $repository = $this->getRepository();
     if ($location->invisible) {
         throw new NotFoundHttpException("Location #{$location->id} cannot be displayed as it is flagged as invisible.");
     }
     $content = $repository->getContentService()->loadContentByContentInfo($location->getContentInfo());
     // Getting language for the current siteaccess
     $languages = $this->getConfigResolver()->getParameter('languages');
     // Using the criteria helper (a demobundle custom service) to generate our query's criteria.
     // This is a good practice in order to have less code in your controller.
     $criteria = $this->get('ezdemo.criteria_helper')->generateListBlogPostCriterion($location, $viewParameters, $languages);
     // Generating query
     $query = new Query();
     $query->query = $criteria;
     $query->sortClauses = array(new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0]));
     // Initialize pagination.
     $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->getRepository()->getSearchService()));
     $pager->setMaxPerPage($this->container->getParameter('ezdemo.blog.blog_post_list.limit'));
     $pager->setCurrentPage($request->get('page', 1));
     return $this->render('eZDemoBundle:full:blog.html.twig', array('location' => $location, 'content' => $content, 'pagerBlog' => $pager), $response);
 }
开发者ID:vidarl,项目名称:DemoBundle,代码行数:39,代码来源:DemoController.php

示例7: indexAction

 public function indexAction(Request $request)
 {
     //mini formulaire d'abonnement
     $news = new Newsletter();
     $form = $this->createFormBuilder($news)->add('news', 'email')->add('Envoyer', 'submit')->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $email = $news->getNews();
         $message = \Swift_Message::newInstance()->setSubject('Bonjour')->setFrom($email)->setTo('stefchrys@yahoo.fr')->setBody('Bonjour Fabrice cet email : ' . $email . ' souhaite un abonnement à votre newsletter, cordialement');
         $this->get('mailer')->send($message);
         return $this->redirect($this->generateUrl('front_homepage'));
     }
     $essais = $this->getCat('essais');
     $arr = $this->get('front.base.service')->recupInfo();
     $arr['essais'] = $essais;
     $arr['nav_accueil'] = ' ';
     $arr['nav_xix'] = ' ';
     $arr['nav_essais'] = 'active';
     $arr['nav_litt'] = ' ';
     $arr['nav_audio'] = ' ';
     $arr['nav_video'] = ' ';
     $arr['nav_info'] = ' ';
     $arr['newsletter'] = $form->createView();
     $response = new Response();
     if ($this->getRequest()->isMethod('GET')) {
         $response->setPublic();
         $response->setSharedMaxAge(1);
         $response->setVary(array('Accept-Encoding', 'User-Agent'));
     }
     return $this->render('FrontBundle:Essais:index.html.twig', $arr, $response);
 }
开发者ID:stefchrys,项目名称:dores,代码行数:31,代码来源:EssaisController.php

示例8: packagesAction

 /**
  * @Template()
  * @Route("/packages.json", name="packages", defaults={"_format" = "json"})
  */
 public function packagesAction()
 {
     // fallback if any of the dumped files exist
     $rootJson = $this->container->getParameter('kernel.root_dir') . '/../web/packages_root.json';
     if (file_exists($rootJson)) {
         return new Response(file_get_contents($rootJson));
     }
     $rootJson = $this->container->getParameter('kernel.root_dir') . '/../web/packages.json';
     if (file_exists($rootJson)) {
         return new Response(file_get_contents($rootJson));
     }
     $em = $this->get('doctrine')->getEntityManager();
     gc_enable();
     $packages = $em->getRepository('Packagist\\WebBundle\\Entity\\Package')->getFullPackages();
     $notifyUrl = $this->generateUrl('track_download', array('name' => 'VND/PKG'));
     $data = array('notify' => str_replace('VND/PKG', '%package%', $notifyUrl), 'packages' => array());
     foreach ($packages as $package) {
         $versions = array();
         foreach ($package->getVersions() as $version) {
             $versions[$version->getVersion()] = $version->toArray();
             $em->detach($version);
         }
         $data['packages'][$package->getName()] = $versions;
         $em->detach($package);
     }
     unset($versions, $package, $packages);
     $response = new Response(json_encode($data), 200);
     $response->setSharedMaxAge(120);
     return $response;
 }
开发者ID:ronnylt,项目名称:packagist,代码行数:34,代码来源:ApiController.php

示例9: 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

示例10: userLinksAction

 /**
  * Renders page header links with cache control
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function userLinksAction()
 {
     $response = new Response();
     $response->setSharedMaxAge(3600);
     $response->setVary('Cookie');
     return $this->render("BCPageLayoutOverrideTestBundle::page_header_links.html.twig", array(), $response);
 }
开发者ID:brookinsconsulting,项目名称:bcpagelayoutoverridetestbundle,代码行数:12,代码来源:BCPageLayoutOverrideTestController.php

示例11: 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

示例12: topMenuAction

 /**
  * Controller  for top menu
  * @param int $currentLocationId
  *
  * @return Response
  */
 public function topMenuAction($currentLocationId)
 {
     $rootLocationId = $this->getConfigResolver()->getParameter('content.tree_root.location_id');
     $response = new Response();
     $parameters = array();
     $helper = $this->get('bananamanu_simple_design.subelement_helper');
     $menu = $helper->getSubElementLocation($rootLocationId);
     // Get current master
     try {
         $currentLocation = $this->getRepository()->getLocationService()->loadLocation($currentLocationId);
         $pathString = explode('/', $currentLocation->pathString);
         if ((int) $pathString[3] > 0) {
             $currentMasterLocationId = $pathString[3];
         } else {
             $currentMasterLocationId = $rootLocationId;
         }
     } catch (\Exception $e) {
         $currentMasterLocationId = $rootLocationId;
     }
     // Get current user
     $user = $this->getRepository()->getCurrentUser();
     // Cache control
     $response->setSharedMaxAge(84600);
     $response->setVary('X-User-Hash');
     $response->setPublic();
     $parameters['menu'] = $menu;
     $parameters['user'] = $user;
     $parameters['currentMasterLocationId'] = $currentMasterLocationId;
     return $this->render('BananamanuSimpleDesignBundle::page_topmenu.html.twig', $parameters, $response);
 }
开发者ID:bananamanu,项目名称:SimpleDesignBundle,代码行数:36,代码来源:MenuController.php

示例13: testSetSharedMaxAge

 public function testSetSharedMaxAge()
 {
     $response = new Response();
     $response->setSharedMaxAge(20);
     $cacheControl = $response->headers->get('Cache-Control');
     $this->assertEquals('public, s-maxage=20', $cacheControl);
 }
开发者ID:neokensou,项目名称:symfony,代码行数:7,代码来源:ResponseTest.php

示例14: renderTag

 /**
  * Renders the tag.
  *
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderTag(Tag $tag, Request $request)
 {
     $configResolver = $this->getConfigResolver();
     if ($this->adapter instanceof TagAdapterInterface) {
         $this->adapter->setTag($tag);
     }
     $pager = new Pagerfanta($this->adapter);
     $pager->setMaxPerPage($configResolver->getParameter('tag_view.related_content_list.limit', 'eztags'));
     $pager->setCurrentPage($request->get('page', 1));
     $response = new Response();
     $response->headers->set('X-Tag-Id', $tag->id);
     if ($configResolver->getParameter('tag_view.cache', 'eztags') === true) {
         $response->setPublic();
         if ($configResolver->getParameter('tag_view.ttl_cache', 'eztags') === true) {
             $response->setSharedMaxAge($configResolver->getParameter('tag_view.default_ttl', 'eztags'));
         }
         // Make the response vary against X-User-Hash header ensures that an HTTP
         // reverse proxy caches the different possible variations of the
         // response as it can depend on user role for instance.
         if ($request->headers->has('X-User-Hash')) {
             $response->setVary('X-User-Hash');
         }
         $response->setLastModified($tag->modificationDate);
     }
     return $this->render($configResolver->getParameter('tag_view.template', 'eztags'), array('tag' => $tag, 'pager' => $pager), $response);
 }
开发者ID:umanit,项目名称:TagsBundle,代码行数:34,代码来源:TagViewController.php

示例15: 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


注:本文中的Symfony\Component\HttpFoundation\Response::setSharedMaxAge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。