Skip to content

Commit 68a8518

Browse files
committed
Added extended JSON methods to ItemPool API
1 parent 9b98932 commit 68a8518

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/phpFastCache/Cache/ExtendedCacheItemPoolInterface.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ public function getItem($key);
7474
*/
7575
public function getItems(array $keys = []);
7676

77+
/**
78+
* Returns A json string that represents an array of items.
79+
*
80+
* @param array $keys
81+
* An indexed array of keys of items to retrieve.
82+
* @param int $option json_encode() options
83+
* @param int $depth json_encode() depth
84+
*
85+
* @throws InvalidArgumentException
86+
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
87+
* MUST be thrown.
88+
*
89+
* @return string
90+
*/
91+
public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512);
92+
7793
/**
7894
* @param \Psr\Cache\CacheItemInterface $item
7995
* @return mixed
@@ -121,6 +137,22 @@ public function getItemsByTag($tagName);
121137
*/
122138
public function getItemsByTags(array $tagNames);
123139

140+
/**
141+
* Returns A json string that represents an array of items by tags-based.
142+
*
143+
* @param array $tagNames
144+
* An indexed array of keys of items to retrieve.
145+
* @param int $option json_encode() options
146+
* @param int $depth json_encode() depth
147+
*
148+
* @throws InvalidArgumentException
149+
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
150+
* MUST be thrown.
151+
*
152+
* @return string
153+
*/
154+
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512);
155+
124156
/**
125157
* Removes the item from the pool by tag.
126158
*

src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818

1919
trait ExtendedCacheItemPoolTrait
2020
{
21+
/**
22+
* @param array $keys
23+
* An indexed array of keys of items to retrieve.
24+
* @param int $option json_encode() options
25+
* @param int $depth json_encode() depth
26+
* @return string
27+
* @throws \InvalidArgumentException
28+
*/
29+
public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512)
30+
{
31+
return json_encode(array_values($this->getItems($keys)), $option, $depth);
32+
}
33+
2134
/**
2235
* @param string $tagName
2336
* @return \phpFastCache\Cache\ExtendedCacheItemInterface[]
@@ -54,6 +67,25 @@ public function getItemsByTags(array $tagNames)
5467
return $items;
5568
}
5669

70+
/**
71+
* Returns A json string that represents an array of items by tags-based.
72+
*
73+
* @param array $tagNames
74+
* An indexed array of keys of items to retrieve.
75+
* @param int $option json_encode() options
76+
* @param int $depth json_encode() depth
77+
*
78+
* @throws InvalidArgumentException
79+
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
80+
* MUST be thrown.
81+
*
82+
* @return string
83+
*/
84+
public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512)
85+
{
86+
return json_encode(array_values($this->getItemsByTags($tagNames)), $option, $depth);
87+
}
88+
5789
/**
5890
* @param string $tagName
5991
* @return bool|null

0 commit comments

Comments
 (0)