host = $host; $this->user = $user; $this->password = $password; } /** * @param array $request * @return array */ public function get(array $request) // TODO-R: :array { // returns a response from external service } } cache = $cache; } public function setLogger(LoggerInterface $logger) { $this->logger = $logger; } /** * {@inheritdoc} */ public function getResponse(array $input) { try { $cacheKey = $this->getCacheKey($input); $cacheItem = $this->cache->getItem($cacheKey); if ($cacheItem->isHit()) { return $cacheItem->get(); } $result = parent::get($input); $cacheItem ->set($result) ->expiresAt( (new DateTime())->modify('+1 day') // TODO-R: обычно TTL устанавливается в секундах. ); return $result; } catch (Exception $e) { // TODO-R: хотелось бы сообщение от ошибке и трейс $this->logger->critical('Error'); } return []; } public function getCacheKey(array $input) { // TODO-R: нет контроля длины ключа. Лучше добавить хеширование. В memcache можно получить ошибку и не записать данные return json_encode($input); } }