From b0c10a028a645acec252fb09548f5cb907f5691c Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Thu, 1 May 2025 21:58:02 -0500 Subject: [PATCH] patch: caches torrentio movie results --- src/Controller/TorrentioController.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Controller/TorrentioController.php b/src/Controller/TorrentioController.php index 2bd25f4..963fcf6 100644 --- a/src/Controller/TorrentioController.php +++ b/src/Controller/TorrentioController.php @@ -20,13 +20,21 @@ final class TorrentioController extends AbstractController ) {} #[Route('/torrentio/movies/{tmdbId}/{imdbId}', name: 'app_torrentio_movies')] - public function movieOptions(GetMovieOptionsInput $input): Response + public function movieOptions(GetMovieOptionsInput $input, CacheInterface $cache): Response { - $results = $this->getMovieOptionsHandler->handle($input->toCommand()); + $cacheId = sprintf( + "page.torrentio.movies.%s.%s", + $input->tmdbId, + $input->imdbId + ); - return $this->render('torrentio/movies.html.twig', [ - 'results' => $results, - ]); + return $cache->get($cacheId, function (ItemInterface $item) use ($input) { + $item->expiresAt(new \DateTimeImmutable("today 11:59 pm")); + $results = $this->getMovieOptionsHandler->handle($input->toCommand()); + return $this->render('torrentio/movies.html.twig', [ + 'results' => $results, + ]); + }); } #[Route('/torrentio/tvshows/{tmdbId}/{imdbId}/{season?}/{episode?}', name: 'app_torrentio_tvshows')]