cacheTtl = config('cache_prices.ttl', 3600); $this->cachePrefix = config('cache_prices.prefix', 'zonneplan:'); } #[Override] public function retrieveElectricity(): Collection { $raw = $this->remember( 'electricity:upcoming', fn () => $this->client->getElectricityPrices()->toArray() ); return ElectricityData::collect($raw, Collection::class); } #[Override] public function retrieveGas(): Collection { $raw = $this->remember( 'gas:upcoming', fn () => $this->client->getGasPrices()->toArray() ); return GasData::collect($raw, Collection::class); } #[Override] public function retrieveElectricityForDate(Carbon $date): Collection { $raw = $this->remember( 'electricity:' . $date->format('Y-m-d'), fn () => $this->client->getElectricityPricesForDate($date)->toArray() ); return ElectricityData::collect($raw, Collection::class); } #[Override] public function retrieveGasForDate(Carbon $date): Collection { $raw = $this->remember( 'gas:' . $date->format('Y-m-d'), fn () => $this->client->getGasPricesForDate($date)->toArray() ); return GasData::collect($raw, Collection::class); } /** * Cache via JSON encoding to ensure clean array structure on retrieval. * * @param callable(): array $callback * @return array */ private function remember(string $key, callable $callback): array { $cached = Cache::remember( $this->cachePrefix . $key, $this->cacheTtl, fn () => json_encode($callback()) ); return json_decode($cached, true); } }