38 lines
787 B
PHP
38 lines
787 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\ScoringGuide;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class AuditionCacheService
|
|
{
|
|
protected $cacheKey = 'auditions';
|
|
/**
|
|
* Create a new class instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
public function getAuditions(): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
return Cache::rememberForever($this->cacheKey, function () {
|
|
return Audition::with(['scoringGuide.subscores'])->get()->keyBy('id');
|
|
});
|
|
}
|
|
|
|
public function getAudition($id)
|
|
{
|
|
return $this->getAuditions()->firstWhere('id',$id);
|
|
}
|
|
|
|
public function refreshCache()
|
|
{
|
|
Cache::forget($this->cacheKey);
|
|
$this->getAuditions();
|
|
}
|
|
}
|