@@ -26,6 +26,14 @@ class CachedHttpClient extends HttpClient
26
26
*/
27
27
private $ lastCachedResponse ;
28
28
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
+
29
37
/**
30
38
* @return CacheInterface
31
39
*/
@@ -54,13 +62,13 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers
54
62
$ response = parent ::request ($ path , $ body , $ httpMethod , $ headers , $ options );
55
63
56
64
if (304 == $ response ->getStatusCode ()) {
57
- $ cacheResponse = $ this ->getCache ()->get ($ path );
65
+ $ cacheResponse = $ this ->getCache ()->get ($ this -> id );
58
66
$ this ->lastCachedResponse = $ cacheResponse ;
59
67
60
68
return $ cacheResponse ;
61
69
}
62
70
63
- $ this ->getCache ()->set ($ path , $ response );
71
+ $ this ->getCache ()->set ($ this -> id , $ response );
64
72
65
73
return $ response ;
66
74
}
@@ -73,8 +81,14 @@ public function request($path, $body = null, $httpMethod = 'GET', array $headers
73
81
protected function createRequest ($ httpMethod , $ path , $ body = null , array $ headers = array (), array $ options = array ())
74
82
{
75
83
$ 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
+ }
76
90
77
- if ($ modifiedAt = $ this ->getCache ()->getModifiedSince ($ path )) {
91
+ if ($ modifiedAt = $ this ->getCache ()->getModifiedSince ($ this -> id )) {
78
92
$ modifiedAt = new \DateTime ('@ ' .$ modifiedAt );
79
93
$ modifiedAt ->setTimezone (new \DateTimeZone ('GMT ' ));
80
94
@@ -83,7 +97,7 @@ protected function createRequest($httpMethod, $path, $body = null, array $header
83
97
sprintf ('%s GMT ' , $ modifiedAt ->format ('l, d-M-y H:i:s ' ))
84
98
);
85
99
}
86
- if ($ etag = $ this ->getCache ()->getETag ($ path )) {
100
+ if ($ etag = $ this ->getCache ()->getETag ($ this -> id )) {
87
101
$ request ->addHeader (
88
102
'If-None-Match ' ,
89
103
$ etag
0 commit comments