Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Fix Ttl & getMaxAge #38

Merged
merged 1 commit into from
Aug 13, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Guzzle/Plugin/Cache/DefaultCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ public function __construct($cache, $keyPrefix = '', $defaultTtl = 3600)
public function cache(RequestInterface $request, Response $response)
{
$currentTime = time();
$ttl = $request->getParams()->get('cache.override_ttl') ?: $response->getMaxAge() ?: $this->defaultTtl;

$overrideTtl = $request->getParams()->get('cache.override_ttl');
if ($overrideTtl) {
$ttl = $overrideTtl;
} else {
$maxAge = $response->getMaxAge();
if ($maxAge !== null) {
$ttl = $maxAge;
} else {
$ttl = $this->defaultTtl;
}
}

if ($cacheControl = $response->getHeader('Cache-Control')) {
$stale = $cacheControl->getDirective('stale-if-error');
Expand Down