Implemenitng Route caching

Hi
I just read https://www.slimframework.com/docs/v4/objects/routing.html#route-expressions-caching and I create the file but now how to implement it?
I’m using Slim 4

Thanks

Hi! The cache file will be generated and used automatically when you define it, as shown in the example.

Justo so see if I understand I just need to add

$routeCollector = $app->getRouteCollector();
$routeCollector->setCacheFile('/path/to/cache.php');

after my route definitions and this first will create the file and next will load the route from here, not from the definition above?

Yes, this is how it should work.

You add the slim routes and on the first request the cache file is automatically created (by FastRoute). The next request then uses the cache file. Make sure that your application has write access to this path.

Note that Slim itself does not use this FastRoute cache file because it defines its own internal route structure only in memory. So finally, it makes no sense to enable this cache file, because you still need to define all routes for Slim.