Posts Learn Components Snippets Categories Tags Tools About
/

How to Cache Route and Cache Config in Laravel 8

Learn the way to cache laravel route and config to better enhance your application loading speed

Created on Jun 26, 2021

221 views

In Laravel, each time a request is made will pass through the lifecycle of the application up till it returns a response. During each of those requests, the routes and configs are read to get the right data and value.

To speed this up you can cache both route and config by running the command below.

Cache the Route


To cache the route, you can run the "route:cache" artisan command. This command will cache all the URLs defined on "/routes" directory.
php artisan route:cache

Cache the Config


To cache the config you can use "config:cache" artisan command and this command will cache the configurations that's defined from "/config" directory.
php artisan config:cache
Do note that any new configuration you have included won't take effect until you "clear" the cache. To clear the cache you can run:
php artisan route:clear
And for the config run it like below.
php artisan config:clear

Other Reads

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

)