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


PHP RequestInterface::getCacheControlDirective方法代码示例

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


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

示例1: canResponseSatisfyRequest

 /**
  * Check if a cache response satisfies a request's caching constraints
  *
  * @param RequestInterface $request  Request to validate
  * @param Response         $response Response to validate
  *
  * @return bool
  */
 public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
 {
     $responseAge = $response->getAge();
     // Check the request's max-age header against the age of the response
     if ($request->hasCacheControlDirective('max-age') && $responseAge > $request->getCacheControlDirective('max-age')) {
         return false;
     }
     // Check the response's max-age header
     if ($response->isFresh() === false) {
         $maxStale = $request->getCacheControlDirective('max-stale');
         if (null !== $maxStale) {
             if ($maxStale !== true && $response->getFreshness() < -1 * $maxStale) {
                 return false;
             }
         } elseif ($response->hasCacheControlDirective('max-age') && $responseAge > $response->getCacheControlDirective('max-age')) {
             return false;
         }
     }
     // Only revalidate GET requests
     if ($request->getMethod() == RequestInterface::GET) {
         // Check if the response must be validated against the origin server
         if ($request->getHeader('Pragma') == 'no-cache' || $request->hasCacheControlDirective('no-cache') || $request->hasCacheControlDirective('must-revalidate') || $response->hasCacheControlDirective('must-revalidate') || $response->hasCacheControlDirective('no-cache')) {
             // no-cache: When no parameters are present, always revalidate
             // When parameters are present in no-cache and the request includes those same parameters, then the
             // response must re-validate. I'll need an example of what fields look like in order to implement a
             // smarter version of no-cache
             // Requests can decline to revalidate against the origin server by setting the cache.revalidate param:
             // - never - To never revalidate and always contact the origin server
             // - skip  - To skip revalidation and just use what is in cache
             switch ($request->getParams()->get('cache.revalidate')) {
                 case 'never':
                     return false;
                 case 'skip':
                     return true;
                 default:
                     return $this->revalidation->revalidate($request, $response);
             }
         }
     }
     return true;
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:49,代码来源:CachePlugin.php

示例2: 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 (is_numeric($requestStaleIfError) && $response->getAge() - $response->getMaxAge() > $requestStaleIfError) {
         return false;
     }
     if (is_numeric($responseStaleIfError) && $response->getAge() - $response->getMaxAge() > $responseStaleIfError) {
         return false;
     }
     return true;
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:23,代码来源:CachePlugin.php


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