本文整理汇总了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));
}