decorated = $decorated; $this->cache = $cache instanceof MultiGetCache && $cache instanceof MultiPutCache ? $cache : new MultiAdapter($cache); $this->baseKey = $baseKey; } /** * @return int */ public function getLifeTime() { return $this->lifeTime; } /** * @param int $lifeTime */ public function setLifeTime($lifeTime) { $this->lifeTime = (int)$lifeTime; } /** * @param array $recordIds * @return \array[] */ public function findByRecordIds(array $recordIds) { $keys = $this->computeKeys($recordIds); $data = $this->cache->fetchMultiple($keys); if (count($data) === count($keys)) { return $data; } $data = $this->decorated->findByRecordIds($recordIds); $this->cache->saveMultiple(array_combine(array_values($keys), array_values($data))); return $data; } /** * @param int[] $recordIds * @return string[] */ private function computeKeys(array $recordIds) { return array_map(function ($recordId) { return $this->baseKey . 'caption' . json_encode([(int)$recordId]); }, $recordIds); } }