1 | <?php |
||
15 | class CachePlugin implements Plugin |
||
16 | { |
||
17 | /** |
||
18 | * @var CacheItemPoolInterface |
||
19 | */ |
||
20 | private $pool; |
||
21 | |||
22 | /** |
||
23 | * Default time to store object in cache. This value is used if CachePlugin::respectCacheHeaders is false or |
||
24 | * if cache headers are missing. |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | private $defaultTtl; |
||
29 | |||
30 | /** |
||
31 | * Look at the cache headers to know how long this response is going to be cached. |
||
32 | * |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $respectCacheHeaders; |
||
36 | |||
37 | /** |
||
38 | * @param CacheItemPoolInterface $pool |
||
39 | * @param array $options |
||
40 | */ |
||
41 | 6 | public function __construct(CacheItemPoolInterface $pool, array $options = []) |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 4 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
79 | |||
80 | /** |
||
81 | * Verify that we can cache this response. |
||
82 | * |
||
83 | * @param ResponseInterface $response |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | 3 | protected function isCacheable(ResponseInterface $response) |
|
100 | |||
101 | /** |
||
102 | * Returns the value of a parameter in the cache control header. If not found we return false. If found with no |
||
103 | * value return true. |
||
104 | * |
||
105 | * @param ResponseInterface $response |
||
106 | * @param string $name |
||
107 | * |
||
108 | * @return bool|string |
||
109 | */ |
||
110 | 2 | private function getCacheControlDirective(ResponseInterface $response, $name) |
|
127 | |||
128 | /** |
||
129 | * @param RequestInterface $request |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 3 | private function createCacheKey(RequestInterface $request) |
|
137 | |||
138 | /** |
||
139 | * Get a ttl in seconds. It could return null if we do not respect cache headers and got no defaultTtl. |
||
140 | * |
||
141 | * @param ResponseInterface $response |
||
142 | * |
||
143 | * @return int|null |
||
144 | */ |
||
145 | 2 | private function getMaxAge(ResponseInterface $response) |
|
170 | } |
||
171 |