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


PHP Response::getVary方法代码示例

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


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


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