1 | <?php |
||
16 | class CachePlugin implements Plugin |
||
17 | { |
||
18 | /** |
||
19 | * @var CacheItemPoolInterface |
||
20 | */ |
||
21 | private $pool; |
||
22 | |||
23 | /** |
||
24 | * @var StreamFactory |
||
25 | */ |
||
26 | private $streamFactory; |
||
27 | |||
28 | /** |
||
29 | * Default time to store object in cache. This value is used if CachePlugin::respectCacheHeaders is false or |
||
30 | * if cache headers are missing. |
||
31 | * |
||
32 | * @var int |
||
33 | */ |
||
34 | private $defaultTtl; |
||
35 | |||
36 | /** |
||
37 | * Look at the cache headers to know how long this response is going to be cached. |
||
38 | * |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $respectCacheHeaders; |
||
42 | |||
43 | /** |
||
44 | * @param CacheItemPoolInterface $pool |
||
45 | * @param StreamFactory $streamFactory |
||
46 | * @param array $options |
||
47 | */ |
||
48 | 6 | public function __construct(CacheItemPoolInterface $pool, StreamFactory $streamFactory, array $options = []) |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 4 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
91 | |||
92 | /** |
||
93 | * Verify that we can cache this response. |
||
94 | * |
||
95 | * @param ResponseInterface $response |
||
96 | * |
||
97 | * @return bool |
||
98 | */ |
||
99 | 3 | protected function isCacheable(ResponseInterface $response) |
|
110 | |||
111 | /** |
||
112 | * Returns the value of a parameter in the cache control header. If not found we return false. If found with no |
||
113 | * value return true. |
||
114 | * |
||
115 | * @param ResponseInterface $response |
||
116 | * @param string $name |
||
117 | * |
||
118 | * @return bool|string |
||
119 | */ |
||
120 | 2 | private function getCacheControlDirective(ResponseInterface $response, $name) |
|
137 | |||
138 | /** |
||
139 | * @param RequestInterface $request |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | 3 | private function createCacheKey(RequestInterface $request) |
|
147 | |||
148 | /** |
||
149 | * Get a ttl in seconds. It could return null if we do not respect cache headers and got no defaultTtl. |
||
150 | * |
||
151 | * @param ResponseInterface $response |
||
152 | * |
||
153 | * @return int|null |
||
154 | */ |
||
155 | 2 | private function getMaxAge(ResponseInterface $response) |
|
180 | } |
||
181 |