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


PHP Response::isCacheable方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\Response::isCacheable方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::isCacheable方法的具體用法?PHP Response::isCacheable怎麽用?PHP Response::isCacheable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\Response的用法示例。


在下文中一共展示了Response::isCacheable方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

示例2: updateMetadata

 /**
  * {@inheritdoc}
  */
 public function updateMetadata(Response $response, BlockContextInterface $blockContext = null)
 {
     if ($this->currentTtl === null) {
         $this->currentTtl = $response->getTtl();
     }
     if ($response->isCacheable() !== null && $response->getTtl() < $this->currentTtl) {
         $this->currentTtl = $response->getTtl();
     }
 }
開發者ID:karousn,項目名稱:SonataBlockBundle,代碼行數:12,代碼來源:HttpCacheHandler.php

示例3: updateHeaders

 private function updateHeaders(Response $response, Response $subResponse)
 {
     if ($this->response->isCacheable() && $subResponse->isCacheable()) {
         $maxAge = (int) min($response->headers->getCacheControlDirective('max-age'), $subResponse->headers->getCacheControlDirective('max-age'));
         $sMaxAge = (int) min($response->headers->getCacheControlDirective('s-maxage'), $subResponse->headers->getCacheControlDirective('s-maxage'));
         $response->setSharedMaxAge($sMaxAge);
         $response->setMaxAge($maxAge);
     } else {
         $this->response->headers->set('Cache-Control', 'no-cache, must-revalidate');
     }
 }
開發者ID:zhil,項目名稱:SSIBundle,代碼行數:11,代碼來源:IncludeHandler.php

示例4: getParameters

 /**
  * {@inheritdoc}
  */
 public function getParameters()
 {
     $code = null;
     $codeType = null;
     $cacheable = null;
     if (null !== $this->response) {
         $code = sprintf('%d', $this->response->getStatusCode());
         $cacheable = $this->response->isCacheable() ? 'cacheable' : 'not_cacheable';
         if ($this->response->isInformational()) {
             $codeType = 'informational';
         } elseif ($this->response->isSuccessful()) {
             $codeType = 'successful';
         } elseif ($this->response->isRedirection()) {
             $codeType = 'redirection';
         } elseif ($this->response->isClientError()) {
             $codeType = 'client_error';
         } elseif ($this->response->isServerError()) {
             $codeType = 'server_error';
         } else {
             $codeType = 'other';
         }
     }
     return array('response_code' => $code, 'response_code_type' => $codeType, 'response_cacheable' => $cacheable);
 }
開發者ID:adrienbrault,項目名稱:statsd-collector,代碼行數:27,代碼來源:SymfonyResponseProvider.php

示例5: addMetaInformation

 /**
  * This method is responsible to cascade ttl to the parent block.
  *
  * @param Response              $response
  * @param BlockContextInterface $blockContext
  * @param BlockServiceInterface $service
  *
  * @return Response
  */
 protected function addMetaInformation(Response $response, BlockContextInterface $blockContext, BlockServiceInterface $service)
 {
     // a response exists, use it
     if ($this->lastResponse && $this->lastResponse->isCacheable()) {
         $response->setTtl($this->lastResponse->getTtl());
         $response->setPublic();
     } elseif ($this->lastResponse) {
         // not cacheable
         $response->setPrivate();
         $response->setTtl(0);
         $response->headers->removeCacheControlDirective('s-maxage');
         $response->headers->removeCacheControlDirective('maxage');
     }
     // no more children available in the stack, reseting the state object
     if (!$blockContext->getBlock()->hasParent()) {
         $this->lastResponse = null;
     } else {
         // contains a parent so storing the response
         $this->lastResponse = $response;
     }
     return $response;
 }
開發者ID:karousn,項目名稱:SonataBlockBundle,代碼行數:31,代碼來源:BlockRenderer.php

示例6: testIsCacheableWithSetTtl

 public function testIsCacheableWithSetTtl()
 {
     $response = new Response();
     $response->setTtl(10);
     $this->assertTrue($response->isCacheable());
 }
開發者ID:BozzaCoon,項目名稱:SPHERE-Framework,代碼行數:6,代碼來源:ResponseTest.php


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