with([ 'serverroot' => url('/'), 'site' => $this->rememberWithCacheFallback('site_settings_array', self::CACHE_TTL, function () { return Settings::query() ->pluck('value', 'name') ->map(fn ($value) => Settings::convertValue($value)) ->all(); }), 'userdata' => $user, 'loggedin' => $user !== null, 'isadmin' => $isNntmuxUser && $user->hasRole('Admin'), 'ismod' => $isNntmuxUser && $user->hasRole('Moderator'), 'userTheme' => $isNntmuxUser ? ($user->theme_preference ?? 'light') : 'light', 'userColorScheme' => $isNntmuxUser ? ($user->color_scheme ?? 'blue') : 'blue', ]); } /** * @param callable(): mixed $callback */ private function rememberWithCacheFallback(string $key, int|\DateInterval $ttl, callable $callback): mixed { try { if (Cache::has($key)) { return Cache::get($key); } $value = $callback(); Cache::put($key, $value, $ttl); return $value; } catch (\Throwable $e) { if (config('app.debug')) { Log::debug('AdminDataComposer cache bypassed: '.$e->getMessage()); } return $callback(); } } }