koel/app/Services/MediaCache.php
2017-01-06 11:04:08 +08:00

27 lines
487 B
PHP

<?php
namespace App\Services;
use App\Models\Artist;
use Cache;
class MediaCache
{
protected $keyName = 'media_cache';
public function get()
{
$data = Cache::get($this->keyName);
if (!$data) {
$data = Artist::orderBy('name')->with('albums', with('albums.songs'))->get();
Cache::forever($this->keyName, $data);
}
return $data;
}
public function clear()
{
Cache::forget($this->keyName);
}
}