1 | <?php |
||
18 | final class CachePlugin implements Plugin |
||
19 | { |
||
20 | /** |
||
21 | * @var CacheItemPoolInterface |
||
22 | */ |
||
23 | private $pool; |
||
24 | |||
25 | /** |
||
26 | * @var StreamFactory |
||
27 | */ |
||
28 | private $streamFactory; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $config; |
||
34 | |||
35 | /** |
||
36 | * @param CacheItemPoolInterface $pool |
||
37 | * @param StreamFactory $streamFactory |
||
38 | * @param array $config { |
||
39 | * |
||
40 | * @var bool $respect_cache_headers Whether to look at the cache directives or ignore them |
||
41 | * @var int $default_ttl If we do not respect cache headers or can't calculate a good ttl, use this value |
||
42 | * @var string $hash_algo The hashing algorithm to use when generating cache keys. |
||
43 | * } |
||
44 | */ |
||
45 | 6 | public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamFactory, array $config = []) |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 4 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
98 | |||
99 | /** |
||
100 | * Verify that we can cache this response. |
||
101 | * |
||
102 | * @param ResponseInterface $response |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | 3 | protected function isCacheable(ResponseInterface $response) |
|
120 | |||
121 | /** |
||
122 | * Get the value of a parameter in the cache control header. |
||
123 | * |
||
124 | * @param ResponseInterface $response |
||
125 | * @param string $name The field of Cache-Control to fetch |
||
126 | * |
||
127 | * @return bool|string The value of the directive, true if directive without value, false if directive not present |
||
128 | */ |
||
129 | 2 | private function getCacheControlDirective(ResponseInterface $response, $name) |
|
146 | |||
147 | /** |
||
148 | * @param RequestInterface $request |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 3 | private function createCacheKey(RequestInterface $request) |
|
156 | |||
157 | /** |
||
158 | * Get a ttl in seconds. It could return null if we do not respect cache headers and got no defaultTtl. |
||
159 | * |
||
160 | * @param ResponseInterface $response |
||
161 | * |
||
162 | * @return int|null |
||
163 | */ |
||
164 | 2 | private function getMaxAge(ResponseInterface $response) |
|
189 | |||
190 | /** |
||
191 | * Configure an options resolver. |
||
192 | * |
||
193 | * @param OptionsResolver $resolver |
||
194 | */ |
||
195 | 6 | private function configureOptions(OptionsResolver $resolver) |
|
207 | } |
||
208 |