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


PHP Response::getMaxAge方法代码示例

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


在下文中一共展示了Response::getMaxAge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: cache

 public function cache(RequestInterface $request, Response $response)
 {
     $currentTime = time();
     $ttl = $request->getParams()->get('cache.override_ttl') ?: $response->getMaxAge() ?: $this->defaultTtl;
     if ($cacheControl = $response->getHeader('Cache-Control')) {
         $stale = $cacheControl->getDirective('stale-if-error');
         $ttl += $stale == true ? $ttl : $stale;
     }
     // Determine which manifest key should be used
     $key = $this->getCacheKey($request);
     $persistedRequest = $this->persistHeaders($request);
     $entries = array();
     if ($manifest = $this->cache->fetch($key)) {
         // Determine which cache entries should still be in the cache
         $vary = $response->getVary();
         foreach (unserialize($manifest) as $entry) {
             // Check if the entry is expired
             if ($entry[4] < $currentTime) {
                 continue;
             }
             $entry[1]['vary'] = isset($entry[1]['vary']) ? $entry[1]['vary'] : '';
             if ($vary != $entry[1]['vary'] || !$this->requestsMatch($vary, $entry[0], $persistedRequest)) {
                 $entries[] = $entry;
             }
         }
     }
     // Persist the response body if needed
     $bodyDigest = null;
     if ($response->getBody() && $response->getBody()->getContentLength() > 0) {
         $bodyDigest = $this->getBodyKey($request->getUrl(), $response->getBody());
         $this->cache->save($bodyDigest, (string) $response->getBody(), $ttl);
     }
     array_unshift($entries, array($persistedRequest, $this->persistHeaders($response), $response->getStatusCode(), $bodyDigest, $currentTime + $ttl));
     $this->cache->save($key, serialize($entries));
 }
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:35,代码来源:DefaultCacheStorage.php

示例2: cache

 /**
  * {@inheritdoc}
  */
 public function cache($key, Response $response, $ttl = null)
 {
     if ($ttl === null) {
         $ttl = $this->defaultTtl;
     }
     $ttl += $response->getMaxAge();
     if ($ttl) {
         $response->setHeader('X-Guzzle-Cache', "key={$key}; ttl={$ttl}");
         // Remove excluded headers from the response  (see RFC 2616:13.5.1)
         foreach ($this->excludeResponseHeaders as $header) {
             $response->removeHeader($header);
         }
         // Add a Date header to the response if none is set (for validation)
         if (!$response->getDate()) {
             $response->setHeader('Date', gmdate(ClientInterface::HTTP_DATE));
         }
         $this->cache->save($key, array($response->getStatusCode(), $response->getHeaders()->getAll(), $response->getBody(true)), $ttl);
     }
 }
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:22,代码来源:DefaultCacheStorage.php

示例3: canResponseSatisfyFailedRequest

 /**
  * Check if a cache response satisfies a failed request's caching constraints
  *
  * @param RequestInterface $request  Request to validate
  * @param Response         $response Response to validate
  *
  * @return bool
  */
 public function canResponseSatisfyFailedRequest(RequestInterface $request, Response $response)
 {
     $reqc = $request->getHeader('Cache-Control');
     $resc = $response->getHeader('Cache-Control');
     $requestStaleIfError = $reqc ? $reqc->getDirective('stale-if-error') : null;
     $responseStaleIfError = $resc ? $resc->getDirective('stale-if-error') : null;
     if (!$requestStaleIfError && !$responseStaleIfError) {
         return false;
     }
     if (is_numeric($requestStaleIfError) && $response->getAge() - $response->getMaxAge() > $requestStaleIfError) {
         return false;
     }
     if (is_numeric($responseStaleIfError) && $response->getAge() - $response->getMaxAge() > $responseStaleIfError) {
         return false;
     }
     return true;
 }
开发者ID:Trideon,项目名称:gigolo,代码行数:25,代码来源:CachePlugin.php

示例4: canResponseSatisfyFailedRequest

 /**
  * Check if a cache response satisfies a failed request's caching constraints
  *
  * @param RequestInterface $request  Request to validate
  * @param Response         $response Response to validate
  *
  * @return bool
  */
 public function canResponseSatisfyFailedRequest(RequestInterface $request, Response $response)
 {
     $requestStaleIfError = $request->getCacheControlDirective('stale-if-error');
     $responseStaleIfError = $response->getCacheControlDirective('stale-if-error');
     if (!$requestStaleIfError && !$responseStaleIfError) {
         return false;
     }
     if ($requestStaleIfError !== true && $requestStaleIfError !== null && $response->getAge() - $response->getMaxAge() > $requestStaleIfError) {
         return false;
     }
     if ($responseStaleIfError !== true && $responseStaleIfError !== null && $response->getAge() - $response->getMaxAge() > $responseStaleIfError) {
         return false;
     }
     return true;
 }
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:23,代码来源:CachePlugin.php


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