Skip to content

Commit bf3e57f

Browse files
authored
Merge pull request #30 from clicksports/bugfix/cache-with-query
fix cache with query
2 parents f128066 + 55aeb6e commit bf3e57f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Traits/CacheResponseTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function setCacheInterface(CacheItemPoolInterface $cache): self
3535
*/
3636
protected function getCacheName(RequestInterface $request): string
3737
{
38-
return 'lex-office-' . str_replace('/', '-', $request->getUri()->getPath());
38+
return 'lex-office-' . str_replace('/', '-', $request->getUri()->getPath()) . $request->getUri()->getQuery();
3939
}
4040

4141

tests/CacheResponseTraitTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ public function testSetCacheResponse($stub)
124124
// test on delete
125125
$stub->setCacheResponse(new Request('DELETE', '/'), $fakeResponse);
126126
$this->assertNull($cacheInterface->getItem($cacheKey)->get());
127+
128+
$cacheInterface->deleteItem($cacheKey);
129+
}
130+
131+
/**
132+
* @depends testSetCacheInterface
133+
*/
134+
public function testDifferentParamsCache($stub)
135+
{
136+
$stub->newRequest('GET', '/?a');
137+
$fakeResponse = new Response(200, [], 'fake');
138+
$stub->setCacheResponse($stub->request, $fakeResponse);
139+
140+
$this->assertEquals(
141+
$this->transformToString($stub->getCacheResponse($stub->request)),
142+
$this->transformToString($fakeResponse)
143+
);
144+
145+
$stub->newRequest('GET', '/?b');
146+
$fakeResponse = new Response(200, [], 'fake2');
147+
$stub->setCacheResponse($stub->request, $fakeResponse);
148+
149+
$this->assertEquals(
150+
$this->transformToString($stub->getCacheResponse($stub->request)),
151+
$this->transformToString($fakeResponse)
152+
);
127153
}
128154

129155
protected function transformToString(ResponseInterface $response)

0 commit comments

Comments
 (0)