repository = $repository; $this->cache = $cache; $this->cacheKey = $cacheKey; } /** * @param int $databoxId * @return \collection[] */ public function findAllByDatabox($databoxId) { $cacheKey = hash('sha256', $this->cacheKey . '.findAll.' . $databoxId); $collections = $this->cache->fetch($cacheKey); if ($collections === false) { $collections = $this->repository->findAllByDatabox($databoxId); $this->save($cacheKey, $collections); } return $collections; } /** * @param int $baseId * @return \collection|null */ public function find($baseId) { $cacheKey = hash('sha256', $this->cacheKey . '.find.' . $baseId); $collection = $this->cache->fetch($cacheKey); if ($collection === false) { $collection = $this->repository->find($baseId); $this->save($cacheKey, $collection); } return $collection; } /** * @param int $databoxId * @param int $collectionId * @return \collection|null */ public function findByCollectionId($databoxId, $collectionId) { $cacheKey = hash('sha256', $this->cacheKey . '.findByCollection.' . $databoxId . $collectionId); $collection = $this->cache->fetch($cacheKey); if ($collection === false) { $collection = $this->repository->findByCollectionId($databoxId, $collectionId); $this->save($cacheKey, $collection); } return $collection; } private function save($key, $value) { $this->cache->save($key, $value); } }