cache->get('bpn_agencies', function (ItemInterface $item) { // Cache for 24 hours (agencies change infrequently) $item->expiresAfter(24 * 60 * 60); $result = $this->apiClient->getAgencies(); if ($result instanceof Notification) { $this->logger->error('Failed to fetch agencies from BPN API', [ 'message' => $result->message, ]); return []; } return $result; }); } catch (InvalidArgumentException $e) { $this->logger->error('Cache error while loading agencies', [ 'exception' => $e->getMessage(), ]); return []; } } public function loadById(int $id): ?Agency { $agencies = $this->loadAll(); foreach ($agencies as $agency) { if ($agency->id === $id) { return $agency; } } return null; } public function loadByCode(string $code): ?Agency { $agencies = $this->loadAll(); foreach ($agencies as $agency) { if ($agency->code === $code) { return $agency; } } return null; } public function loadDefault(): ?Agency { return $this->loadByCode(self::DEFAULT_AGENCY_CODE); } }