@@ -26,6 +26,14 @@ class CachedHttpClient extends HttpClient
2626 */
2727 private $ lastCachedResponse ;
2828
29+ /**
30+ * Identifier used for the cache file(s).
31+ * $path + encoded query parameter(s) if they exist.
32+ *
33+ * @var string
34+ */
35+ private $ id ;
36+
2937 /**
3038 * @return CacheInterface
3139 */
@@ -54,13 +62,13 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers
5462 $ response = parent ::request ($ path , $ body , $ httpMethod , $ headers , $ options );
5563
5664 if (304 == $ response ->getStatusCode ()) {
57- $ cacheResponse = $ this ->getCache ()->get ($ path );
65+ $ cacheResponse = $ this ->getCache ()->get ($ this -> id );
5866 $ this ->lastCachedResponse = $ cacheResponse ;
5967
6068 return $ cacheResponse ;
6169 }
6270
63- $ this ->getCache ()->set ($ path , $ response );
71+ $ this ->getCache ()->set ($ this -> id , $ response );
6472
6573 return $ response ;
6674 }
@@ -73,8 +81,14 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers
7381 protected function createRequest ($ httpMethod , $ path , $ body = null , array $ headers = array (), array $ options = array ())
7482 {
7583 $ request = parent ::createRequest ($ httpMethod , $ path , $ body , $ headers , $ options );
84+
85+ $ this ->id = $ path ;
86+
87+ if (array_key_exists ('query ' , $ options ) && !empty ($ options ['query ' ])) {
88+ $ this ->id .= '? ' . $ request ->getQuery ();
89+ }
7690
77- if ($ modifiedAt = $ this ->getCache ()->getModifiedSince ($ path )) {
91+ if ($ modifiedAt = $ this ->getCache ()->getModifiedSince ($ this -> id )) {
7892 $ modifiedAt = new \DateTime ('@ ' .$ modifiedAt );
7993 $ modifiedAt ->setTimezone (new \DateTimeZone ('GMT ' ));
8094
@@ -83,7 +97,7 @@ protected function createRequest($httpMethod, $path, $body = null, array $header
8397 sprintf ('%s GMT ' , $ modifiedAt ->format ('l, d-M-y H:i:s ' ))
8498 );
8599 }
86- if ($ etag = $ this ->getCache ()->getETag ($ path )) {
100+ if ($ etag = $ this ->getCache ()->getETag ($ this -> id )) {
87101 $ request ->addHeader (
88102 'If-None-Match ' ,
89103 $ etag
0 commit comments