Laravel: clear the cache like a pro
Hundreds of developers subscribed to my newsletter.
Join them and enjoy free content about the art of crafting websites!
Table of contents

How to clear the cache
To clear the cache in Laravel, use the php artisan optimize:clear
command.
Laravel will remove the config cache, the bootstrap cache, the events cache, the application cache, the routes cache and the views cache.
All of these can drastically speed up your applications. But sometimes, it comes in the way of our debugging duties.
Let’s review even more commands to help you have a more granular control over it.
How to clear the application cache (memcached, Redis)
To clear the application cache in Laravel, use the php artisan cache:clear
command.
Depending on your cache driver (defined in your .env file and named CACHE_DRIVER
), Laravel will clear files on disk or data in Redis or memcached.
Now, if you just need to remove one value from the cache, the php artisan cache:forget <key> [store]
does exactly that.
How to clear config cache
To clear the config cache in Laravel, use the php artisan config:clear
command.
Laravel will clear the cache by deleting bootstrap/cache/config.php.
If you previously ran php artisan config:cache
, you can now update values in .env file and see the changes when you run your code. 👍
How to clear events cache
To clear the events cache in Laravel, use the php artisan event:clear
command.
If you previously ran php artisan event:cache
, Laravel will delete bootstrap/cache/events.php and discover all the new listeners you added to your codebase.
Learn more about Laravel’s automatic event discovery.
How to clear routes cache
To clear the routes cache in Laravel, use the php artisan route:clear
command.
If you previously ran php artisan route:cache
, Laravel will remove bootstrap/cache/routes-v7.php and you will be able to see all the new routes you registered using php artisan route:list
.
How to clear scheduled tasks cache
To clear the scheduled tasks cache, use the php artisan schedule:clear-cache
command.
Learn more about Laravel’s tasks overlap prevention, because that’s what this cache is for.
Unless you have good reasons, I discourage you to run this command in production.
How to clear views cache
To clear the views cache, use the php artisan view:clear
command.
Laravel will delete the content of storage/views.
The views cache is generated every time you hit your route unless it already exists and your view didn’t change. You shouldn’t have much need for this command.
Bonus: turn off the application cache
To completely turn off the application cache, change the cache driver to null
in your .env file.
CACHE_DRIVER=null