mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
Use cache() shortcut where applicable
This commit is contained in:
parent
c842ef4db0
commit
1ba00a0475
6 changed files with 13 additions and 16 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use Cache;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Foundation\Application as IlluminateApplication;
|
||||
|
@ -84,7 +83,7 @@ class Application extends IlluminateApplication
|
|||
*/
|
||||
public function getLatestVersion(Client $client = null)
|
||||
{
|
||||
if ($v = Cache::get('latestKoelVersion')) {
|
||||
if ($v = cache('latestKoelVersion')) {
|
||||
return $v;
|
||||
}
|
||||
|
||||
|
@ -93,7 +92,7 @@ class Application extends IlluminateApplication
|
|||
try {
|
||||
$v = json_decode($client->get('https://api.github.com/repos/phanan/koel/tags')->getBody())[0]->name;
|
||||
// Cache for one day
|
||||
Cache::put('latestKoelVersion', $v, 1 * 24 * 60);
|
||||
cache(['latestKoelVersion' => $v], 1 * 24 * 60);
|
||||
|
||||
return $v;
|
||||
} catch (Exception $e) {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Cache;
|
||||
use Exception;
|
||||
use getID3;
|
||||
use getid3_lib;
|
||||
|
@ -356,7 +355,7 @@ class File
|
|||
// As directory scanning can be expensive, we cache and reuse the result.
|
||||
$cacheKey = md5($this->path.'_cover');
|
||||
|
||||
if (!is_null($cover = Cache::get($cacheKey))) {
|
||||
if (!is_null($cover = cache($cacheKey))) {
|
||||
return $cover;
|
||||
}
|
||||
|
||||
|
@ -376,7 +375,7 @@ class File
|
|||
$cover = false;
|
||||
}
|
||||
|
||||
Cache::put($cacheKey, $cover, 24 * 60);
|
||||
cache([$cacheKey => $cover], 24 * 60);
|
||||
|
||||
return $cover;
|
||||
}
|
||||
|
|
|
@ -78,11 +78,11 @@ class Lastfm extends RESTfulService
|
|||
try {
|
||||
$cacheKey = md5("lastfm_artist_$name");
|
||||
|
||||
if ($response = Cache::get($cacheKey)) {
|
||||
if ($response = cache($cacheKey)) {
|
||||
$response = simplexml_load_string($response);
|
||||
} else {
|
||||
if ($response = $this->get("?method=artist.getInfo&autocorrect=1&artist=$name")) {
|
||||
Cache::put($cacheKey, $response->asXML(), 24 * 60 * 7);
|
||||
cache([$cacheKey => $response->asXML()], 24 * 60 * 7);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,11 +127,11 @@ class Lastfm extends RESTfulService
|
|||
try {
|
||||
$cacheKey = md5("lastfm_album_{$name}_{$artistName}");
|
||||
|
||||
if ($response = Cache::get($cacheKey)) {
|
||||
if ($response = cache($cacheKey)) {
|
||||
$response = simplexml_load_string($response);
|
||||
} else {
|
||||
if ($response = $this->get("?method=album.getInfo&autocorrect=1&album=$name&artist=$artistName")) {
|
||||
Cache::put($cacheKey, $response->asXML(), 24 * 60 * 7);
|
||||
cache([$cacheKey => $response->asXML()], 24 * 60 * 7);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Services;
|
||||
|
||||
use App\Models\Song;
|
||||
use Cache;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class YouTube extends RESTfulService
|
||||
|
@ -76,13 +75,13 @@ class YouTube extends RESTfulService
|
|||
);
|
||||
|
||||
$cacheKey = md5("youtube_$uri");
|
||||
if ($response = Cache::get($cacheKey)) {
|
||||
if ($response = cache($cacheKey)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($response = $this->get($uri)) {
|
||||
// Cache the result for 7 days
|
||||
Cache::put($cacheKey, $response, 60 * 24 * 7);
|
||||
cache([$cacheKey => $response], 60 * 24 * 7);
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
|
|
@ -41,7 +41,7 @@ class LastfmTest extends TestCase
|
|||
], $api->getArtistInfo('foo'));
|
||||
|
||||
// Is it cached?
|
||||
$this->assertNotNull(Cache::get(md5('lastfm_artist_foo')));
|
||||
$this->assertNotNull(cache(md5('lastfm_artist_foo')));
|
||||
}
|
||||
|
||||
public function testGetArtistInfoFailed()
|
||||
|
@ -85,7 +85,7 @@ class LastfmTest extends TestCase
|
|||
], $api->getAlbumInfo('foo', 'bar'));
|
||||
|
||||
// Is it cached?
|
||||
$this->assertNotNull(Cache::get(md5('lastfm_album_foo_bar')));
|
||||
$this->assertNotNull(cache(md5('lastfm_album_foo_bar')));
|
||||
}
|
||||
|
||||
public function testGetAlbumInfoFailed()
|
||||
|
|
|
@ -27,7 +27,7 @@ class YouTubeTest extends TestCase
|
|||
$this->assertEquals('Slipknot - Snuff [OFFICIAL VIDEO]', $response->items[0]->snippet->title);
|
||||
|
||||
// Is it cached?
|
||||
$this->assertNotNull(Cache::get('1492972ec5c8e6b3a9323ba719655ddb'));
|
||||
$this->assertNotNull(cache('1492972ec5c8e6b3a9323ba719655ddb'));
|
||||
}
|
||||
|
||||
public function testSearchVideosRelatedToSong()
|
||||
|
|
Loading…
Reference in a new issue