/** * @test */ public function it_builds_a_response_from_a_cached_value() { $properties = ['content' => 'My content', 'statusCode' => 200, 'headers' => new ResponseHeaderBag(['header' => 'value'])]; $cacheParser = new CacheParser(serialize($properties)); $response = $cacheParser->response(); $this->assertEquals($properties['content'], $response->getContent()); $this->assertEquals($properties['statusCode'], $response->getStatusCode()); $this->assertEquals('value', $response->headers->get('header')); }
/** * Retrieve the cache entry for the given Request * * @param Request $request * @return Response|null */ public function get(Request $request) { if (!$this->allowQueries) { return null; } $parsedRequest = new RequestParser($request); $cacheKey = $parsedRequest->cacheKey(); // If the request is not cacheable, return null if (!$cacheKey) { return null; } $cacheValue = $this->repository->get($cacheKey); // If no response was found, return null if (!$cacheValue) { return null; } $parsedResponse = new CacheParser($cacheValue); return $parsedResponse->response(); }