Clear all kinds of caches with a single command in Laravel

Amit Merchant · March 23, 2022 ·

There are mainly three kinds of caches in Laravel that you need to clear all the related junk files and optimize the performance of the application.

Individually clearing caches

Here are all the caches and their related artisan command to clear them up.

  • To flush the application cache
$ php artisan cache:clear
  • To flush the route cache file
$ php artisan route:clear
  • To flush the configuration cache file
$ php artisan config:clear

These commands are fine but I recently got to know about a command that can do all these single-handedly. Thanks to this tweet by Andrew Schmelyun!

One command fits all!

There’s a optimize:clear artisan command that can flush/remove the application cache, route cache, and config cache altogether.

$ php artisan optimize:clear

So, if you’re going to remove all the caches and don’t want to do it individually, you can use this command happily!

Learn the fundamentals of PHP 8 (and 8.1), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-read guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

👋 Hi there! I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Cheers!

Comments?