* * @param Closure(): TValue $read Reads the real value from the database. * @param TValue $whenUnavailable Returned as-is when the database cannot answer. * @return TValue */ public static function rememberForever(string $key, Closure $read, array $whenUnavailable): array { try { return Cache::rememberForever($key, $read); } catch (PDOException $e) { // QueryException extends PDOException, so this covers both a // missing table and a connection that could not be opened. self::warnOnce($key, $e); return $whenUnavailable; } } /** * Once per process: an install that has not been migrated yet would * otherwise log this on every artisan command, and a genuine database * outage would log it on every request. */ private static function warnOnce(string $key, PDOException $e): void { if (self::$warned) { return; } self::$warned = true; Log::warning('Falling back to default settings: the database could not be read during boot.', [ 'key' => $key, 'reason' => $e->getMessage(), ]); } }