getCache()->get($key); if ($item) { $cacheItem = new CacheItem($key, true); $cacheItem->set($item); return $cacheItem; } return new CacheItem($key); } /** * @inheritdoc * * @return CacheItemInterface[] */ public function getItems(array $keys = []) { $items = []; foreach ($keys as $key) { $items[] = $this->getItem($key); } return $items; } /** * @inheritdoc */ public function hasItem($key) { return $this->getCache()->has($key); } /** * @inheritdoc */ public function clear() { return $this->getCache()->clear(); } /** * @inheritdoc */ public function deleteItem($key) { return $this->getCache()->delete($key); } /** * @inheritdoc */ public function deleteItems(array $keys) { return $this->getCache()->deleteMultiple($keys); } /** * @inheritdoc */ public function save(CacheItemInterface $item) { return $this->store($item); } /** * @inheritdoc */ public function saveDeferred(CacheItemInterface $item) { $this->deferred[$item->getKey()] = $item; return true; } /** * @inheritdoc */ public function commit() { foreach ($this->deferred as $item) { if (!$this->store($item)) { return false; } } return true; } private function getCache(): CacheInterface { if ($this->hasOption(self::OPTION_CACHE_SERVICE)) { return $this->getOption(self::OPTION_CACHE_SERVICE); } return $this->getServiceLocator()->get(SimpleCache::SERVICE_ID); } private function store(CacheItemInterface $item): bool { try { return $this->getCache()->set($item->getKey(), $item->get()); } catch (Throwable $exception) { $this->getLogger()->error( sprintf( 'Cache value for %s key has not been saved. %s', $item->getKey(), $exception->getMessage() ) ); return false; } } }