diff --git a/lib/Github/HttpClient/CachedHttpClient.php b/lib/Github/HttpClient/CachedHttpClient.php index f0e1368e6f3..c753fe4ab07 100644 --- a/lib/Github/HttpClient/CachedHttpClient.php +++ b/lib/Github/HttpClient/CachedHttpClient.php @@ -26,6 +26,14 @@ class CachedHttpClient extends HttpClient */ private $lastCachedResponse; + /** + * Identifier used for the cache file(s). + * $path + encoded query parameter(s) if they exist. + * + * @var string + */ + private $id; + /** * @return CacheInterface */ @@ -54,13 +62,13 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers $response = parent::request($path, $body, $httpMethod, $headers, $options); if (304 == $response->getStatusCode()) { - $cacheResponse = $this->getCache()->get($path); + $cacheResponse = $this->getCache()->get($this->id); $this->lastCachedResponse = $cacheResponse; return $cacheResponse; } - $this->getCache()->set($path, $response); + $this->getCache()->set($this->id, $response); return $response; } @@ -73,8 +81,14 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers protected function createRequest($httpMethod, $path, $body = null, array $headers = array(), array $options = array()) { $request = parent::createRequest($httpMethod, $path, $body, $headers, $options); + + $this->id = $path; + + if (array_key_exists('query', $options) && !empty($options['query'])) { + $this->id .= '?' . $request->getQuery(); + } - if ($modifiedAt = $this->getCache()->getModifiedSince($path)) { + if ($modifiedAt = $this->getCache()->getModifiedSince($this->id)) { $modifiedAt = new \DateTime('@'.$modifiedAt); $modifiedAt->setTimezone(new \DateTimeZone('GMT')); @@ -83,7 +97,7 @@ protected function createRequest($httpMethod, $path, $body = null, array $header sprintf('%s GMT', $modifiedAt->format('l, d-M-y H:i:s')) ); } - if ($etag = $this->getCache()->getETag($path)) { + if ($etag = $this->getCache()->getETag($this->id)) { $request->addHeader( 'If-None-Match', $etag