From de88a365459ee4cae4f0f145c84ef98fceee2514 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Sun, 22 Jun 2025 22:44:58 -0500 Subject: [PATCH] feat: creates cache pools for torrentio & tmdb --- config/packages/cache.yaml | 7 +++++-- src/Tmdb/Tmdb.php | 8 ++++---- src/Torrentio/Client/Torrentio.php | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/config/packages/cache.yaml b/config/packages/cache.yaml index c554045..5a6ab9f 100644 --- a/config/packages/cache.yaml +++ b/config/packages/cache.yaml @@ -15,5 +15,8 @@ framework: #app: cache.adapter.apcu # Namespaced pools use the above "app" backend by default - #pools: - #my.dedicated.cache: null + pools: + torrentio.cache: + adapter: cache.app + tmdb.cache: + adapter: cache.app diff --git a/src/Tmdb/Tmdb.php b/src/Tmdb/Tmdb.php index 587cd1a..3a663b9 100644 --- a/src/Tmdb/Tmdb.php +++ b/src/Tmdb/Tmdb.php @@ -44,7 +44,7 @@ class Tmdb const POSTER_IMG_PATH = "https://image.tmdb.org/t/p/w500"; public function __construct( - private readonly CacheItemPoolInterface $cache, + private readonly CacheItemPoolInterface $tmdbCache, private readonly EventDispatcherInterface $eventDispatcher, #[Autowire(env: 'TMDB_API')] string $apiKey, ) { @@ -78,7 +78,7 @@ class Tmdb $requestListener = new Psr6CachedRequestListener( $this->client->getHttpClient(), $this->eventDispatcher, - $cache, + $tmdbCache, $this->client->getHttpClient()->getPsr17StreamFactory(), [] ); @@ -325,7 +325,7 @@ class Tmdb public function getImdbId(string $tmdbId, $mediaType) { - $externalIds = $this->cache->get("tmdb.externalIds.{$tmdbId}", + $externalIds = $this->tmdbCache->get("tmdb.externalIds.{$tmdbId}", function (ItemInterface $item) use ($tmdbId, $mediaType) { switch (MediaType::tryFrom($mediaType)->value) { case MediaType::Movie->value: @@ -346,7 +346,7 @@ class Tmdb public function getImages($tmdbId, $mediaType) { - return $this->cache->get("tmdb.images.{$tmdbId}", + return $this->tmdbCache->get("tmdb.images.{$tmdbId}", function (ItemInterface $item) use ($tmdbId, $mediaType) { switch (MediaType::tryFrom($mediaType)->value) { case MediaType::Movie->value: diff --git a/src/Torrentio/Client/Torrentio.php b/src/Torrentio/Client/Torrentio.php index d9fef60..25b14a9 100644 --- a/src/Torrentio/Client/Torrentio.php +++ b/src/Torrentio/Client/Torrentio.php @@ -23,7 +23,7 @@ class Torrentio public function __construct( #[Autowire(env: 'REAL_DEBRID_KEY')] private string $realDebridKey, - private TagAwareCacheInterface $cache, + private TagAwareCacheInterface $torrentioCache, private LoggerInterface $logger, ) { $this->searchUrl = str_replace('{realDebridKey}', $this->realDebridKey, $this->baseUrl); @@ -36,7 +36,7 @@ class Torrentio { $cacheKey = "torrentio.{$imdbCode}"; - $results = $this->cache->get($cacheKey, function (ItemInterface $item) use ($imdbCode, $type) { + $results = $this->torrentioCache->get($cacheKey, function (ItemInterface $item) use ($imdbCode, $type) { $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); $item->tag(['torrentio', $type, $imdbCode]); try { @@ -62,7 +62,7 @@ class Torrentio public function fetchEpisodeResults(string $imdbId, int $season, int $episode): array { $cacheKey = "torrentio.$imdbId.$season.$episode"; - $results = $this->cache->get($cacheKey, function (ItemInterface $item) use ($imdbId, $season, $episode) { + $results = $this->torrentioCache->get($cacheKey, function (ItemInterface $item) use ($imdbId, $season, $episode) { $item->expiresAt(Carbon::now()->addHour()->setMinute(0)->setSecond(0)); $item->tag(['torrentio', 'tvshows', 'torrentio.tvshows', $imdbId, "torrentio.$imdbId", "$imdbId.$season", "torrentio.$imdbId.$season", "$imdbId.$season.$episode", "torrentio.$imdbId.$season.$episode"]); try {