$expiry_seconds) { return false; // expired → force refresh via API } $contents = @file_get_contents($file); return $contents !== false ? $contents : false; } return false; } /** * Store artifact to cache (filesystem). * * @param string $key * @param string $html * @return void */ public static function set($key, $html) { $file = self::file_path($key); $dir = dirname($file); if (!is_dir($dir)) { wp_mkdir_p($dir); } @file_put_contents($file, $html); } /** * Map key to file path under uploads. * * @param string $key * @return string */ private static function file_path($key) { $uploads = wp_upload_dir(); $base = trailingslashit($uploads['basedir']) . 'ai-translate/cache/'; // Extract language from key: ait:v2:site:lang:route:ver $parts = explode(':', (string) $key); $lang = isset($parts[3]) ? sanitize_key($parts[3]) : 'xx'; $dir = $base . $lang . '/pages/'; $hash = md5($key); return $dir . substr($hash, 0, 2) . '/' . $hash . '.html'; } }