Skip to content

Commit 70dcd5d

Browse files
committed
Fixed did not support multiple tag headers
1 parent 33b6538 commit 70dcd5d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Psr6Store.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ public function write(Request $request, Response $response)
231231
// Tags
232232
$tags = [];
233233
if ($response->headers->has($this->options['cache_tags_header'])) {
234-
$tags = explode(',', $response->headers->get($this->options['cache_tags_header']));
234+
foreach ($response->headers->get($this->options['cache_tags_header'], '', false) as $header) {
235+
foreach (explode(',', $header) as $tag) {
236+
$tags[] = $tag;
237+
}
238+
}
235239
}
236240

237241
// Prune expired entries on file system if needed

tests/Psr6StoreTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ public function testWriteAddsTags()
230230
$this->assertFalse($this->getCache()->getItem($cacheKey)->isHit());
231231
}
232232

233+
public function testWriteAddsTagsWithMultipleHeaders()
234+
{
235+
$request = Request::create('/');
236+
$response = new Response('hello world', 200);
237+
$response->headers->set('Cache-Tags', ['foobar,other tag', 'some,more', 'tags', 'split,over', 'multiple-headers']);
238+
239+
$cacheKey = $this->store->getCacheKey($request);
240+
241+
$this->store->write($request, $response);
242+
243+
$this->assertTrue($this->getCache()->getItem($cacheKey)->isHit());
244+
$this->assertTrue($this->store->invalidateTags(['multiple-headers']));
245+
$this->assertFalse($this->getCache()->getItem($cacheKey)->isHit());
246+
}
247+
233248
public function testInvalidateTagsThrowsExceptionIfWrongCacheAdapterProvided()
234249
{
235250
$this->expectException(\RuntimeException::class);

0 commit comments

Comments
 (0)