userInfoService = $userInfoService; $this->logger = $logger; $this->cache = $cache; } /** * @param int $userId * @return array * @throws InvalidArgumentException */ public function getUserInfo(int $userId): array { $userKey = 'list:user:' . $userId; if ($this->cache->has($userKey)) { // echo "Getting user {$userId} from cache\n"; $this->logger->log('Getting user ' . $userId . ' from cache' . PHP_EOL); return $this->cache->get($userKey); } $this->logger->log('Getting user ' . $userId . ' from service' . PHP_EOL); $userInfo = $this->userInfoService->getUserInfo($userId); $this->cache->set($userKey, $userInfo, 3600); return $userInfo; } }