Slim 3 - Route Caching

I’ve updated Slim Framework 3.0 to 3.5 on my server and I noticed that a new option named routerCacheFile for settings have been added.

So as the documentation says I’ve choosen a valid PHP writable file so I can test it and see how it works. Everything worked fine, the file was filled with the route caching on the first run.

My question is: What benefits does this brings ? The answer can be in the PRO/CON format. I want just to know if this impact somehow in the perfomance since is disabled by default.

Note that I don’t know what this option does, would be appreciated if someone explained to me in a few words this options.

It is used for the caching in FastRoute

The benefit of caching should be performance.

I guess the reason its off by default it that it only makes sense in production.

1 Like


Caching will improve performance especially when there are more number of endpoints. say for example 500+

I was not aware of this option and came with a solution for my new project :

The routerCacheFile option should makes things simple.

Please have a look at the Comments received there

1 Like

To QUICKLY view performance difference, with and without caching : integrate Tracy - PHP debugger.

  • The entire site is interactive, try it.
  • Tracy bar shows execution time.
  • Explore by fetching random routes with and without cache.
  • Delete the cache file to start fresh.

###Tracy debugger stopwatch
( copy paste from github project page )

Another useful tool is the debugger stopwatch with a precision of microseconds:


// sweet dreams my cherrie

$elapsed = Debugger::timer();
// $elapsed = 2

Multiple measurements at once can be achieved by an optional parameter.

// some code

// some code

$rssElapsed = Debugger::timer('rss-generating');
$pageElapsed = Debugger::timer('page-generating');
Debugger::timer(); // runs the timer

... // some time consuming operation

echo Debugger::timer(); // elapsed time in seconds


More about debugger for slim3

1 Like

It would seem that this is used only in FastCache. From the point of view of a slim application, does this mean that my ‘workflow’ still requires me to define all my routes but than I simply do a


after defining my routes? Also, where in the application should this be placed? I think router is created in Slim itself, so what’s the proper place to do a setCacheFile() ?