koel/app/Services/MediaCache.php

32 lines
630 B
PHP
Raw Normal View History

2017-01-06 03:04:08 +00:00
<?php
namespace App\Services;
use App\Models\Artist;
use Cache;
class MediaCache
{
protected $keyName = 'media_cache';
public function get()
{
2017-01-15 04:27:05 +00:00
if (!config('koel.cache_media')) {
return Artist::orderBy('name')->with('albums', with('albums.songs'))->get();
}
2017-01-06 03:04:08 +00:00
$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);
}
}