diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index dfbe6630f31..95e6913b373 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -18,6 +18,13 @@ class CachedHttpClient extends HttpClient * @var CacheInterface */ protected $cache; + + /** + * contains the lastResponse fetched from cache + * + * @var Guzzle\Http\Message\Response + */ + private $lastCachedResponse; /** * @return CacheInterface @@ -45,9 +52,12 @@ public function setCache(CacheInterface $cache) public function request($path, $body = null, $httpMethod = 'GET', array $headers = array(), array $options = array()) { $response = parent::request($path, $body, $httpMethod, $headers, $options); - + if (304 == $response->getStatusCode()) { - return $this->getCache()->get($path); + $cacheResponse = $this->getCache()->get($path); + $this->lastCachedResponse = $cacheResponse; + + return $cacheResponse; } $this->getCache()->set($path, $response); @@ -82,4 +92,18 @@ protected function createRequest($httpMethod, $path, $body = null, array $header return $request; } + + /** + * @return Guzzle\Http\Message\Response + */ + public function getLastResponse($force = false) + { + + $lastResponse = parent::getLastResponse(); + if (304 != $lastResponse->getStatusCode()) { + $force = true; + } + + return ($force) ? $lastResponse : $this->lastCachedResponse; + } }