@@ -181,7 +181,7 @@ protected function doHandleRequest(RequestInterface $request, callable $next, ca
181
181
return $ this ->handleCacheListeners ($ request , $ this ->createResponseFromCacheItem ($ cacheItem ), true , $ cacheItem );
182
182
}
183
183
184
- if ($ this ->isCacheable ($ request , $ response )) {
184
+ if ($ this ->isCacheable ($ response ) && $ this -> isCacheableRequest ( $ request )) {
185
185
$ bodyStream = $ response ->getBody ();
186
186
$ body = $ bodyStream ->__toString ();
187
187
if ($ bodyStream ->isSeekable ()) {
@@ -244,26 +244,37 @@ private function calculateResponseExpiresAt($maxAge)
244
244
/**
245
245
* Verify that we can cache this response.
246
246
*
247
- * @param RequestInterface $request
248
247
* @param ResponseInterface $response
249
248
*
250
249
* @return bool
251
250
*/
252
- protected function isCacheable (RequestInterface $ request , ResponseInterface $ response )
251
+ protected function isCacheable (ResponseInterface $ response )
253
252
{
254
253
if (!in_array ($ response ->getStatusCode (), [200 , 203 , 300 , 301 , 302 , 404 , 410 ])) {
255
254
return false ;
256
255
}
257
256
258
- foreach ($ this ->config ['blacklisted_paths ' ] as $ not_to_cache_path ) {
259
- if (1 === preg_match ('/ ' .$ not_to_cache_path .'/ ' , $ request ->getRequestTarget ())) {
257
+ $ nocacheDirectives = array_intersect ($ this ->config ['respect_response_cache_directives ' ], $ this ->noCacheFlags );
258
+ foreach ($ nocacheDirectives as $ nocacheDirective ) {
259
+ if ($ this ->getCacheControlDirective ($ response , $ nocacheDirective )) {
260
260
return false ;
261
261
}
262
262
}
263
263
264
- $ nocacheDirectives = array_intersect ($ this ->config ['respect_response_cache_directives ' ], $ this ->noCacheFlags );
265
- foreach ($ nocacheDirectives as $ nocacheDirective ) {
266
- if ($ this ->getCacheControlDirective ($ response , $ nocacheDirective )) {
264
+ return true ;
265
+ }
266
+
267
+ /**
268
+ * Verify that we can cache this request.
269
+ *
270
+ * @param RequestInterface $request
271
+ *
272
+ * @return bool
273
+ */
274
+ protected function isCacheableRequest (RequestInterface $ request )
275
+ {
276
+ foreach ($ this ->config ['blacklisted_paths ' ] as $ not_to_cache_path ) {
277
+ if (1 === preg_match ('/ ' .$ not_to_cache_path .'/ ' , $ request ->getRequestTarget ())) {
267
278
return false ;
268
279
}
269
280
}
@@ -358,7 +369,7 @@ private function configureOptions(OptionsResolver $resolver)
358
369
'respect_response_cache_directives ' => ['no-cache ' , 'private ' , 'max-age ' , 'no-store ' ],
359
370
'cache_key_generator ' => null ,
360
371
'cache_listeners ' => [],
361
- 'blacklisted_paths ' => [], // restricted for
372
+ 'blacklisted_paths ' => [],
362
373
]);
363
374
364
375
$ resolver ->setAllowedTypes ('cache_lifetime ' , ['int ' , 'null ' ]);
0 commit comments