diff --git a/app/Services/ZaarboxPriceService.php b/app/Services/ZaarboxPriceService.php index 040decb..031349f 100644 --- a/app/Services/ZaarboxPriceService.php +++ b/app/Services/ZaarboxPriceService.php @@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Log; class ZaarboxPriceService { - public const CACHE_KEY = 'zaarbox_gold_prices'; + private const CACHE_KEY_PREFIX = 'zaarbox_gold_prices'; private const CACHE_TTL_MINUTES = 35; @@ -33,9 +33,14 @@ class ZaarboxPriceService return $chartId ?: self::HISTORY_ID; } + private function cacheKey(): string + { + return self::CACHE_KEY_PREFIX . ':' . $this->historyId(); + } + public function getAllPrices(): array { - $cached = Cache::get(self::CACHE_KEY); + $cached = Cache::get($this->cacheKey()); if (is_array($cached) && isset($cached['prices'])) { return $cached['prices']; @@ -48,7 +53,7 @@ class ZaarboxPriceService { $prices = $this->fetchAllPrices(); - Cache::put(self::CACHE_KEY, [ + Cache::put($this->cacheKey(), [ 'prices' => $prices, 'refreshed_at' => now()->toIso8601String(), ], now()->addMinutes(self::CACHE_TTL_MINUTES));