Skip to content
Antares

Route Caching

Reflecting over controller classes on every request adds overhead. Route caching compiles the route map once and stores it as a plain PHP file.

$cachePath = __DIR__ . '/../storage/cache/routes.php';
if (file_exists($cachePath)) {
$router->loadFromCache($cachePath);
} else {
$router->register(UserController::class);
$router->register(PostController::class);
$router->saveToCache($cachePath);
}

When using the full Antares framework, caching is handled automatically when APP_ENV=production:

  • On boot, if storage/cache/routes.php exists and the fingerprint still matches, routes are loaded from the cache.
  • Otherwise the route providers run, and the result is written to the cache.

The fingerprint is a hash of composer.lock, .env, and every file under app/, so changing any of them rebuilds the cache on the next boot.

Clear the cache manually (run from the project root):

Terminal window
php vendor/bin/antares cache:clear