Skip to content

Commit cec149b

Browse files
committed
Implement caching types
1 parent c8dfcc5 commit cec149b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/CachePlugin.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamF
5858
$this->config = $optionsResolver->resolve($config);
5959
}
6060

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+
6174
/**
6275
* {@inheritdoc}
6376
*/
@@ -186,8 +199,11 @@ protected function isCacheable(ResponseInterface $response)
186199
if (!$this->config['respect_cache_headers']) {
187200
return true;
188201
}
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+
}
191207
}
192208

193209
return true;
@@ -279,6 +295,7 @@ private function configureOptions(OptionsResolver $resolver)
279295
'respect_cache_headers' => true,
280296
'hash_algo' => 'sha1',
281297
'methods' => ['GET', 'HEAD'],
298+
'excluded_directives' => ['no-cache', 'private'],
282299
]);
283300

284301
$resolver->setAllowedTypes('cache_lifetime', ['int', 'null']);

0 commit comments

Comments
 (0)