cache = $cache; $this->defaultTtl = $defaultTtl; } 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()->toArray(), $response->getBody(true)), $ttl ); } } public function delete($key) { $this->cache->delete($key); } public function fetch($key) { return $this->cache->fetch($key); } }