RouteCache
Solo\Router\RouteCache keeps a built Router in a PHP file, so a request loads it from OPcache instead of registering and building routes. See Route Cache for usage, deployment, and limitations.
use Solo\Router\RouteCache;
$cache = new RouteCache('/var/www/app/var/cache/routes.php');load()
public function load(callable $define): RouterReturns the router stored in the file. When the file is missing, or was written by an incompatible version of the package, calls $define with a new RouteCollector, builds the router, saves it, and returns it.
$router = $cache->load(function (RouteCollector $routes): void {
$routes->get('/users/{id}', [UserController::class, 'show']);
});Throws:
InvalidArgumentExceptionfor invalid definitions, asbuild()does;LogicExceptionif a handler, middleware, or attribute contains a closure or another object;RuntimeExceptionif the file cannot be written.
save()
public function save(Router $router): voidWrites the router to the file, replacing it atomically, and invalidates the file in OPcache. Missing directories are created. Throws LogicException for routes that cannot be cached and RuntimeException if the file cannot be written.
clear()
public function clear(): voidDeletes the file, if it exists, and invalidates it in OPcache, so the next load() builds the router again. Throws RuntimeException if the file cannot be deleted.