Skip to content

Commit

Permalink
refactor: rename getCachedResponse() to get()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 3, 2023
1 parent 3603477 commit 5a950f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function make($request, ResponseInterface $response, int $ttl): bool
*
* @param CLIRequest|IncomingRequest $request
*/
public function getCachedResponse($request, ResponseInterface $response): ?ResponseInterface
public function get($request, ResponseInterface $response): ?ResponseInterface
{
if ($cachedResponse = $this->cache->get($this->generateCacheKey($request))) {
$cachedResponse = unserialize($cachedResponse);
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ protected function forceSecureAccess($duration = 31_536_000)
*/
public function displayCache(Cache $config)
{
if ($cachedResponse = $this->pageCache->getCachedResponse($this->request, $this->response)) {
if ($cachedResponse = $this->pageCache->get($this->request, $this->response)) {
$this->response = $cachedResponse;

$this->totalTime = $this->benchmark->getElapsedTime('total_execution');
Expand Down
20 changes: 10 additions & 10 deletions tests/system/Cache/ResponseCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ public function testCachePageIncomingRequest()

// Check cache with a request with the same URI path.
$request = $this->createIncomingRequest('foo/bar');
$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());
$this->assertSame('abcd1234', $cachedResponse->getHeaderLine('ETag'));

// Check cache with a request with the same URI path and different query string.
$request = $this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']);
$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());
Expand All @@ -124,7 +124,7 @@ public function testCachePageIncomingRequest()
// Check cache with another request with the different URI path.
$request = $this->createIncomingRequest('another');

$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
}
Expand All @@ -147,22 +147,22 @@ public function testCachePageIncomingRequestWithCacheQueryString()

// Check cache with a request with the same URI path and same query string.
$this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']);
$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());
$this->assertSame('abcd1234', $cachedResponse->getHeaderLine('ETag'));

// Check cache with a request with the same URI path and different query string.
$request = $this->createIncomingRequest('foo/bar', ['xfoo' => 'bar', 'bar' => 'baz']);
$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);

// Check cache with another request with the different URI path.
$request = $this->createIncomingRequest('another');

$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
}
Expand All @@ -182,15 +182,15 @@ public function testCachePageCLIRequest()

// Check cache with a request with the same params.
$request = $this->createCLIRequest(['foo', 'bar']);
$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame('The response body.', $cachedResponse->getBody());

// Check cache with another request with the different params.
$request = $this->createCLIRequest(['baz']);

$cachedResponse = $pageCache->getCachedResponse($request, new Response($this->appConfig));
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public function testUnserializeError()
$cache->save($cacheKey, 'Invalid data');

// Check cache with a request with the same URI path.
$pageCache->getCachedResponse($request, new Response($this->appConfig));
$pageCache->get($request, new Response($this->appConfig));
}

public function testInvalidCacheError()
Expand All @@ -244,6 +244,6 @@ public function testInvalidCacheError()
$cache->save($cacheKey, serialize(['a' => '1']));

// Check cache with a request with the same URI path.
$pageCache->getCachedResponse($request, new Response($this->appConfig));
$pageCache->get($request, new Response($this->appConfig));
}
}

0 comments on commit 5a950f0

Please sign in to comment.