auditionCache = $auditionCache; } /** * Return a collection of all entries for the provided auditionId along with the * student.school for each entry. * @param $auditionId * @return \Illuminate\Database\Eloquent\Collection */ public function getEntriesForAudition($auditionId) { $cacheKey = 'audition' . $auditionId . 'entries'; return Cache::remember($cacheKey, 3600, function () use ($auditionId) { return Entry::where('audition_id',$auditionId) ->with('student.school') ->get() ->keyBy('id'); }); } /** * Returns a collection of collections of entries, one collection for each audition. * The outer collection is keyed by the audition ID. The included entries are * with their student.school. * @return Collection */ public function getAllEntriesByAudition(): Collection { $auditions = $this->auditionCache->getAuditions(); $allEntries = []; foreach ($auditions as $audition) { $allEntries[$audition->id] = $this->getEntriesForAudition($audition->id); } return collect($allEntries); } public function getAllEntries() { $cacheKey = 'allEntries'; return Cache::remember($cacheKey, 3600, function() { return Entry::with(['student.school'])->get()->keyBy('id'); }); } public function clearEntryCacheForAudition($auditionId): void { $cacheKey = 'audition' . $auditionId . 'entries'; Cache::forget($cacheKey); Cache::forget('allEntries'); } public function clearEntryCaches(): void { $auditions = $this->auditionCache->getAuditions(); foreach ($auditions as $audition) { $this->clearEntryCacheForAudition($audition->id); } } }