public function findByIds(array $ids, $useCache = true) { if (!$useCache) { return parent::findByIds($ids, false); } $objects = []; foreach ($ids as $i => $id) { if (isset($this->objectByIdCache[$id])) { $objects[] = $this->objectByIdCache[$id]; unset($ids[$i]); } } if (empty($ids)) { return $objects; } $keys = array_map(function ($id) { return $this->getCacheKey($id); }, $ids); $cachedData = $this->cache->fetchMultiple($keys); foreach ($cachedData as $data) { $object = $this->restoreFromCache($data); $objects[] = $object; unset($ids[array_search($object->getId(), $ids)]); } if (empty($ids)) { return $objects; } $fromDb = parent::findByIds($ids, false); $this->storeMultipleInCache($fromDb); return array_merge($objects, $fromDb); }
public function findByIds(array $ids, $useCache = true) { if ($useCache && empty($this->objectByIdCache)) { $this->findAll(); } return parent::findByIds($ids); }