Laravel Artisan Route Command: The route:cache Command

December 7, 2016 —John Koster

The route:cache command is used to create a route cache file. This cache file will improve the performance of the route registration process. This command accepts no parameters or options. This command will be unable to cache any routes that use a closure as its action. The following is an example of a route which uses a closure as its action:

1Route::get('/', function() {
2 return view('welcome');
3});

In order to use route caching, all routes must be registered using controller classes. The following routes file could be cached:

1<?php
2 
3Route::get('/', [
4 'uses' => 'HomeController@index',
5 'as' => 'home'
6]);

Running the route:cache command is straightforward:

1# Cache the applications routes.
2php artisan route:cache

The cache file will be stored in the bootstrap/cache/routes.php file. Routes are cached as serialized objects stored stored using base 64 encoding.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.