Skip to content

Commit

Permalink
feat: add HTTP method to web page cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Dec 25, 2023
1 parent ec67f73 commit 0c01fbc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Cache/ResponseCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function generateCacheKey($request): string
? $uri->getQuery(is_array($this->cacheQueryString) ? ['only' => $this->cacheQueryString] : [])
: '';

return md5((string) $uri->setFragment('')->setQuery($query));
return md5($request->getMethod() . ':' . $uri->setFragment('')->setQuery($query));
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/system/Cache/ResponseCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ public function testCachePageIncomingRequestWithCacheQueryString()
$this->assertNull($cachedResponse);
}

public function testCachePageIncomingRequestWithHttpMethods()
{
$pageCache = $this->createResponseCache();

$request = $this->createIncomingRequest('foo/bar');

$response = new Response($this->appConfig);
$response->setBody('The response body.');

$return = $pageCache->make($request, $response);

$this->assertTrue($return);

// Check cache with a request with the same URI path and different HTTP method
$request = $this->createIncomingRequest('foo/bar')->withMethod('POST');
$cachedResponse = $pageCache->get($request, new Response($this->appConfig));

$this->assertNull($cachedResponse);
}

public function testCachePageCLIRequest()
{
$pageCache = $this->createResponseCache();
Expand Down

0 comments on commit 0c01fbc

Please sign in to comment.