3 namespace seekat\API\Call\Cache\Service
;
5 use http\Client\Response
;
6 use Psr\Cache\CacheItemInterface
;
7 use Psr\Cache\CacheItemPoolInterface
;
8 use seekat\API\Call\Cache\Service
;
10 final class ItemPool
implements Service
{
11 private ?CacheItemInterface
$item;
13 public function __construct(private readonly CacheItemPoolInterface
$cache) {
18 * @param Response|null $response
20 * @throws \Psr\Cache\InvalidArgumentException
22 public function fetch(string $key, Response
&$response = null) : bool {
23 $this->item
= $this->cache
->getItem($key);
24 if ($this->item
->isHit()) {
25 $response = $this->item
->get();
31 public function store(string $key, Response
$response) : bool {
32 $this->item
->set($response);
33 return $this->cache
->save($this->item
);
38 * @throws \Psr\Cache\InvalidArgumentException
40 public function del(string $key) : void
{
41 $this->cache
->deleteItem($key);
44 public function clear() : void
{
45 $this->cache
->clear();