connect('127.0.0.1', 6379); $useRedis = true; } } catch (Exception $e) { error_log("Redis not available: " . $e->getMessage()); } if ($useRedis && $redis->exists($cacheKey)) { $genre = json_decode($redis->get($cacheKey), true); } else { $apiUrl = "$postgrestUrl/optimized_genres?url=eq./" . $url; $client = new Client(); try { $response = $client->request("GET", $apiUrl, [ "headers" => [ "Accept" => "application/json", "Authorization" => "Bearer {$postgrestApiKey}", ], ]); $genreData = json_decode($response->getBody(), true); if (!$genreData) { echo file_get_contents(__DIR__ . "/../../404/index.html"); exit(); } $genre = $genreData[0]; if ($useRedis) { $redis->setex($cacheKey, 3600, json_encode($genre)); } } catch (Exception $e) { error_log($e->getMessage()); echo file_get_contents(__DIR__ . "/../../404/index.html"); exit(); } } $pageTitle = htmlspecialchars("Genres • " . $genre["name"], ENT_QUOTES, "UTF-8"); $pageDescription = truncateText(htmlspecialchars(strip_tags($genre["description"]), ENT_QUOTES, "UTF-8"), 250); $ogImage = htmlspecialchars($genre["artists"][0]["image"], ENT_QUOTES, "UTF-8"); $fullUrl = "https://www.coryd.dev" . $requestUri; ob_start(); header("Cache-Control: public, max-age=3600"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); ?>