@@ -58,6 +58,19 @@ public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamF
58
58
$ this ->config = $ optionsResolver ->resolve ($ config );
59
59
}
60
60
61
+ public static function clientCache (CacheItemPoolInterface $ pool , StreamFactory $ streamFactory , array $ config = [])
62
+ {
63
+ // Allow caching of private requests
64
+ $ config ['excluded_directives ' ] = ['no-cache ' ];
65
+
66
+ self ::__construct ($ pool , $ streamFactory , $ config );
67
+ }
68
+
69
+ public static function serverCache (CacheItemPoolInterface $ pool , StreamFactory $ streamFactory , array $ config = [])
70
+ {
71
+ self ::__construct ($ pool , $ streamFactory , $ config );
72
+ }
73
+
61
74
/**
62
75
* {@inheritdoc}
63
76
*/
@@ -186,8 +199,11 @@ protected function isCacheable(ResponseInterface $response)
186
199
if (!$ this ->config ['respect_cache_headers ' ]) {
187
200
return true ;
188
201
}
189
- if ($ this ->getCacheControlDirective ($ response , 'no-store ' ) || $ this ->getCacheControlDirective ($ response , 'private ' )) {
190
- return false ;
202
+
203
+ foreach ($ this ->config ['excluded_directives ' ] as $ cacheDirective ) {
204
+ if ($ this ->getCacheControlDirective ($ response , $ cacheDirective )) {
205
+ return false ;
206
+ }
191
207
}
192
208
193
209
return true ;
@@ -279,6 +295,7 @@ private function configureOptions(OptionsResolver $resolver)
279
295
'respect_cache_headers ' => true ,
280
296
'hash_algo ' => 'sha1 ' ,
281
297
'methods ' => ['GET ' , 'HEAD ' ],
298
+ 'excluded_directives ' => ['no-cache ' , 'private ' ],
282
299
]);
283
300
284
301
$ resolver ->setAllowedTypes ('cache_lifetime ' , ['int ' , 'null ' ]);
0 commit comments