Skip to content

Commit 2f1bbdb

Browse files
committed
Fixed Json formatting + tags behaviour
1 parent 2d9d5cf commit 2f1bbdb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace phpFastCache\Core;
1616

1717
use InvalidArgumentException;
18+
use Psr\Cache\CacheItemInterface;
1819

1920
trait ExtendedCacheItemPoolTrait
2021
{
@@ -28,7 +29,10 @@ trait ExtendedCacheItemPoolTrait
2829
*/
2930
public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512)
3031
{
31-
return json_encode(array_values($this->getItems($keys)), $option, $depth);
32+
$callback = function(CacheItemInterface $item){
33+
return $item->get();
34+
};
35+
return json_encode(array_map($callback, array_values($this->getItems($keys))), $option, $depth);
3236
}
3337

3438
/**
@@ -39,9 +43,9 @@ public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512
3943
public function getItemsByTag($tagName)
4044
{
4145
if (is_string($tagName)) {
42-
$driverResponse = $this->driverRead($this->getTagKey($tagName));
43-
if ($driverResponse) {
44-
$items = (array) $this->driverUnwrapData($driverResponse);
46+
$driverResponse = $this->getItem($this->getTagKey($tagName));
47+
if ($driverResponse->isHit()) {
48+
$items = (array) $driverResponse->get();
4549

4650
return $this->getItems(array_unique(array_keys($items)));
4751
} else {
@@ -83,7 +87,11 @@ public function getItemsByTags(array $tagNames)
8387
*/
8488
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512)
8589
{
86-
return json_encode(array_values($this->getItemsByTags($tagNames)), $option, $depth);
90+
$callback = function(CacheItemInterface $item){
91+
return $item->get();
92+
};
93+
94+
return json_encode(array_map($callback, array_values($this->getItemsByTags($tagNames))), $option, $depth);
8795
}
8896

8997
/**

0 commit comments

Comments
 (0)