input->getMethod() !== 'POST') { $this->sendJson(405, ['error' => 'POST required']); return; } $user = $app->getIdentity(); if (!$user->authorise('core.manage', 'com_plugins')) { $this->sendJson(403, ['error' => 'Not authorized']); return; } try { $cache = Factory::getCache(''); $cache->clean(''); $adminCache = Factory::getCache('', 'callback', 'administrator'); $adminCache->clean(''); if (function_exists('opcache_reset')) { opcache_reset(); } $this->sendJson(200, [ 'status' => 'ok', 'message' => 'Cache cleared', ]); } catch (\Throwable $e) { $this->sendJson(500, [ 'error' => 'Cache clear failed', 'message' => $e->getMessage(), ]); } } /** * @param int $code HTTP status code * @param array $payload Response data * @return void */ private function sendJson(int $code, array $payload): void { $app = Factory::getApplication(); $app->setHeader('Content-Type', 'application/json', true); $app->setHeader('Status', (string) $code, true); echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); $app->close(); } }