getAge() публичный Метод

Returns the age of the response.
public getAge ( ) : integer
Результат integer The age of the response in seconds
Пример #1
0
 public function testUpdateResponse()
 {
     $this->response->setPublic()->shouldBeCalled();
     $this->response->setMaxAge($this->maxAge)->shouldBeCalled();
     $this->response->setSharedMaxAge($this->sharedMaxAge)->shouldBeCalled();
     $this->structure->getCacheLifeTime()->willReturn(10);
     $this->response->getAge()->willReturn(50);
     $this->handler->updateResponse($this->response->reveal(), $this->structure->reveal());
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     // mark the response as either public or private
     $response->setPublic();
     // set the private and shared max age
     $response->setMaxAge($this->maxAge);
     $response->setSharedMaxAge($this->sharedMaxAge);
     $proxyTtl = $this->usePageTtl ? $response->getAge() + intval($structure->getCacheLifeTime()) : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }
Пример #3
0
 /**
  * Returns the response reverse-proxy cache TTL in seconds.
  *
  * @param Response $response
  *
  * @return int|null The TTL in seconds
  */
 private function getReverseProxyTtl(Response $response)
 {
     if (null !== ($maxAge = $response->headers->get(self::HEADER_REVERSE_PROXY_TTL))) {
         return $maxAge - $response->getAge();
     }
     return;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     $cacheLifetimeData = $structure->getCacheLifeTime();
     $cacheLifetime = $this->cacheLifetimeResolver->resolve($cacheLifetimeData['type'], $cacheLifetimeData['value']);
     // when structure cache-lifetime disabled - return
     if (0 === $cacheLifetime) {
         return;
     }
     // mark the response as either public or private
     $response->setPublic();
     // set the private and shared max age
     $response->setMaxAge($this->maxAge);
     $response->setSharedMaxAge($this->sharedMaxAge);
     $proxyTtl = $this->usePageTtl ? $response->getAge() + $cacheLifetime : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }
Пример #5
0
 /**
  * Returns a rendered xmlsitemap.
  *
  * @return Response
  */
 public function indexAction(Request $request)
 {
     /** @var RequestAnalyzerInterface $requestAnalyzer */
     $requestAnalyzer = $this->get('sulu_core.webspace.request_analyzer');
     /** @var SitemapXMLGeneratorInterface $sitemapXMLGenerator */
     $sitemapXMLGenerator = $this->get('sulu_website.sitemap_xml_generator');
     $sitemap = $this->get('sulu_content.content_repository')->findAll($requestAnalyzer->getWebspace()->getXDefaultLocalization()->getLocalization(), $requestAnalyzer->getWebspace()->getKey(), MappingBuilder::create()->addProperties(['changed'])->setResolveUrl(true)->getMapping());
     $webspaceSitemaps = [['localizations' => array_map(function (Localization $localization) {
         return $localization->getLocalization();
     }, $requestAnalyzer->getWebspace()->getAllLocalizations()), 'defaultLocalization' => $requestAnalyzer->getWebspace()->getXDefaultLocalization()->getLocalization(), 'sitemap' => $sitemap]];
     $preferredDomain = $request->getHttpHost();
     // XML Response
     $response = new Response();
     $response->setMaxAge(240);
     $response->setSharedMaxAge(960);
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime'));
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($sitemapXMLGenerator->generate($webspaceSitemaps, $preferredDomain, $request->getScheme()));
     // Generate XML
     return $response;
 }
Пример #6
0
 /**
  * Returns a rendered xmlsitemap.
  *
  * @return Response
  */
 public function indexAction(Request $request)
 {
     /** @var RequestAnalyzerInterface $requestAnalyzer */
     $requestAnalyzer = $this->get('sulu_core.webspace.request_analyzer');
     /** @var SitemapGeneratorInterface $sitemapGenerator */
     $sitemapGenerator = $this->get('sulu_website.sitemap');
     /** @var SitemapXMLGeneratorInterface $sitemapXMLGenerator */
     $sitemapXMLGenerator = $this->get('sulu_website.sitemap_xml_generator');
     $flatSitemap = true;
     $webspaceSitemaps = [$sitemapGenerator->generateAllLocals($requestAnalyzer->getWebspace()->getKey(), $flatSitemap)];
     $preferredDomain = $request->getHttpHost();
     // XML Response
     $response = new Response();
     $response->setMaxAge(240);
     $response->setSharedMaxAge(960);
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime'));
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($sitemapXMLGenerator->generate($webspaceSitemaps, $preferredDomain));
     // Generate XML
     return $response;
 }
Пример #7
0
 public function testSetClientTtl()
 {
     $response = new Response();
     $response->setClientTtl(10);
     $this->assertEquals($response->getMaxAge(), $response->getAge() + 10);
 }
Пример #8
0
 /**
  * Set cache headers.
  *
  * @param Response $response
  *
  * @return Response
  */
 private function setCacheLifetime(Response $response)
 {
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime'));
     return $response->setMaxAge(240)->setSharedMaxAge(960);
 }