summaryrefslogtreecommitdiff
path: root/app/Http/Controllers/AnimeController.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Http/Controllers/AnimeController.php')
-rw-r--r--app/Http/Controllers/AnimeController.php51
1 files changed, 44 insertions, 7 deletions
diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php
index 0a3d3b4..265617e 100644
--- a/app/Http/Controllers/AnimeController.php
+++ b/app/Http/Controllers/AnimeController.php
@@ -20,6 +20,10 @@ class AnimeController extends Controller {
*/
public function showAnime($mal_id, $slug = "") {
+ if ( Cache::has($mal_id) ) {
+ return Cache::get($mal_id);
+ }
+
$anime = Anime::where('mal_id', $mal_id)->get()->first();
if ( is_null($anime) ) {
abort(404);
@@ -112,10 +116,18 @@ class AnimeController extends Controller {
$anime["basic_data"] = DB::select('select score, rank, popularity, members, favorites from anime join stats on stats.id = ( select id from stats where anime.mal_id = stats.mal_id order by created_at desc limit 1) where anime.mal_id = ?', [$mal_id])[0];
- return view('anime', [ "anime" => $anime ]);
+ $cached_data = view('anime', [ "anime" => $anime ])->render();
+
+ Cache::put($mal_id, $cached_data, 6000); // 1000 minutes
+ return $cached_data;
}
public function showCurrentAnime() {
+
+ if ( Cache::has('airing_anime') ) {
+ return Cache::get('airing_anime');
+ }
+
$anime = new Anime;
$anime = $anime->setTable('view_anime_index');
@@ -133,10 +145,18 @@ class AnimeController extends Controller {
$anime = $anime->get();
#$anime = $anime->simplePaginate(10);
- return view('list_anime', ["all_anime" => $anime, "title" => "Currently Airing"]);
+ $cached_data = view('list_anime', ["all_anime" => $anime, "title" => "Currently Airing"])->render();
+
+ Cache::put('airing_anime', $cached_data, 6000); // 100 minutes
+ return $cached_data;
}
- public function showSurprisingAnime() {
+ public function showSurprisingAnime(Request $req) {
+
+ if ( Cache::has('surprising_anime' . $req->get('page')) ) {
+ return Cache::get('surprising_anime' . $req->get('page'));
+ }
+
$anime = new Anime;
$most_surprising_anime = $anime->setTable('view_anime_index');
$most_surprising_anime = $most_surprising_anime->paginate(12);
@@ -144,10 +164,18 @@ class AnimeController extends Controller {
#$most_surprising_anime = $most_surprising_anime->get();
#return view('surprising_anime', ["surprising_anime" => $most_surprising_anime, "title" => "Most Surprising"]);
- return view('list_anime', ["all_anime" => $most_surprising_anime, "title" => "Most Surprising Anime"]);
+ $cached_data = view('list_anime', ["all_anime" => $most_surprising_anime, "title" => "Most Surprising Anime"])->render();
+
+ Cache::put('surprising_anime' . $req->get('page'), $cached_data, 6000); // 100 minutes
+ return $cached_data;
}
- public function showTopAnime() {
+ public function showTopAnime(Request $req) {
+
+ if ( Cache::has('top_anime' . $req->get('page')) ) {
+ return Cache::get('top_anime' . $req->get('page'));
+ }
+
$anime = new Anime;
$anime = $anime->setTable('view_anime_index');
$anime = $anime->orderBy('score_today', 'desc');
@@ -156,7 +184,10 @@ class AnimeController extends Controller {
$top_anime = $anime->paginate(12);
#return view('top_anime', ["top_anime" => $top_anime, "title" => "Top"]);
- return view('list_anime', ["all_anime" => $top_anime, "title" => "Top Anime of all Time"]);
+ $cached_data = view('list_anime', ["all_anime" => $top_anime, "title" => "Top Anime of all Time"])->render();
+
+ Cache::put('top_anime' . $req->get('page'), $cached_data, 6000); // 100 minutes
+ return $cached_data;
}
public function search(Request $request) {
@@ -193,6 +224,10 @@ class AnimeController extends Controller {
public function showSeason($season_year, $season_name = null) {
+ if ( Cache::has($season_year.$season_name) ) {
+ return Cache::get($season_year.$season_name);
+ }
+
$anime = new Anime;
$anime = $anime->setTable('view_anime_index');
@@ -209,7 +244,9 @@ class AnimeController extends Controller {
$sanime = $anime->get();
#$sanime = $anime->paginate(12);
- return view('list_anime', ["all_anime" => $sanime, "title" => $season_name . " Season " . $season_year]);
+ $cached_data = view('list_anime', ["all_anime" => $sanime, "title" => $season_name . " Season " . $season_year])->render();
+ Cache::set($season_year.$season_name, $cached_data, 6000); // 100 minutes
+ return $cached_data;
}
public function changeSeason(Request $request) {