*/ private array $inMemory = []; private const NOT_FOUND = '__SETTING_CACHE_NOT_FOUND__'; /** * Get setting from cache. * Checks in-memory first, then falls through to Laravel cache. */ public function get(string $key): mixed { // Tier 1: In-memory (zero I/O) if (array_key_exists($key, $this->inMemory)) { $value = $this->inMemory[$key]; return $value === self::NOT_FOUND ? null : $value; } // Tier 2: Laravel cache (file/Redis) $value = Cache::get(self::CACHE_KEY_PREFIX.$key); // Store in memory for subsequent reads within this request $this->inMemory[$key] = $value ?? self::NOT_FOUND; return $value; } /** * Store setting in both in-memory and Laravel cache. */ public function set(string $key, mixed $value): void { $this->inMemory[$key] = $value; Cache::put(self::CACHE_KEY_PREFIX.$key, $value, self::CACHE_TTL); } /** * Remove setting from both in-memory and Laravel cache. */ public function forget(string $key): void { unset($this->inMemory[$key]); Cache::forget(self::CACHE_KEY_PREFIX.$key); } /** * Clear all settings from cache. */ public function flush(): void { $this->inMemory = []; Cache::tags(['settings'])->flush(); } }