Conditions | 3 |
Paths | 3 |
Total Lines | 24 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 3 |
CRAP Score | 7.8273 |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | 2 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
14 | { |
||
15 | 2 | if (!$this->shouldCache($request)) { |
|
16 | 2 | return $handler->handle($request); |
|
17 | } |
||
18 | |||
19 | $idGenerator = $this->getIdGenerator(); |
||
20 | $cache = $this->getStorageAdapter(); |
||
21 | |||
22 | $cacheId = $idGenerator->generate($request); |
||
23 | $serialized = $cache->getItem($cacheId, $success, $casToken); |
||
24 | |||
25 | if (!$success) { |
||
26 | $cacheStatus = self::STATUS_MISS; |
||
27 | $response = $handler->handle($request); |
||
28 | $serialized = ResponseSerializer::toArray($response); |
||
29 | $cache->setItem($cacheId, $serialized); |
||
30 | } else { |
||
31 | $cacheStatus = self::STATUS_HIT; |
||
32 | assert(is_array($serialized)); |
||
33 | $response = ResponseSerializer::fromArray($serialized); |
||
34 | } |
||
35 | |||
36 | return $response->withHeader('X-Page-Cache', $cacheStatus); |
||
|
|||
37 | } |
||
39 |