mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Use flexible cache
This commit is contained in:
+10
-32
@@ -363,16 +363,9 @@ class Category extends Model
|
||||
*/
|
||||
public static function getChildren($categoryId)
|
||||
{
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
|
||||
$result = Cache::get(md5($categoryId));
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = RootCategory::find($categoryId)->categories;
|
||||
Cache::put(md5($categoryId), $result, $expiresAt);
|
||||
|
||||
return $result;
|
||||
return Cache::flexible(md5($categoryId), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($categoryId) {
|
||||
return RootCategory::find($categoryId)->categories;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -406,16 +399,9 @@ class Category extends Model
|
||||
public static function getByIds($ids)
|
||||
{
|
||||
if (\count($ids) > 0) {
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
|
||||
$result = Cache::get(md5(implode(',', $ids)));
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
$result = self::query()->whereIn('id', $ids)->get();
|
||||
|
||||
Cache::put(md5(md5(implode(',', $ids))), $result, $expiresAt);
|
||||
|
||||
return $result;
|
||||
return Cache::flexible(md5(md5(implode(',', $ids))), [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () use ($ids) {
|
||||
return self::query()->whereIn('id', $ids)->get();
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -477,21 +463,13 @@ class Category extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* Get categories for the API.
|
||||
*/
|
||||
public static function getForApi()
|
||||
{
|
||||
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_long'));
|
||||
$result = Cache::get(md5('ForApi'));
|
||||
if ($result !== null) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = RootCategory::query()->select(['id', 'title'])->where('status', '=', self::STATUS_ACTIVE)->get();
|
||||
|
||||
Cache::put(md5('ForApi'), $result, $expiresAt);
|
||||
|
||||
return $result;
|
||||
return Cache::flexible('ForApi', [config('nntmux.cache_expiry_medium'), config('nntmux.cache_expiry_long')], function () {
|
||||
return RootCategory::query()->select(['id', 'title'])->where('status', '=', self::STATUS_ACTIVE)->get();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user