Benjamin Crozat The web developer life

Laravel: clear the cache (+ 6 commands for more control)

Benjamin Crozat Benjamin Crozat2 minutes read

Before you start reading this article, did you know 76 persons subscribed to my newsletter?

Join them and enjoy free content about the art of crafting websites!

Laravel: clear the cache (+ 6 commands for more control)
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, bootstrap cache, events cache, general cache (or application cache), routes cache and views cache.

How to clear the application cache

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.

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.

You can now update values in .env file. 👍

How to clear events cache

To clear the events cache in Laravel, use the php artisan event:clear command.

Laravel will delete bootstrap/cache/events.php.

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:cache command.

Laravel will remove bootstrap/cache/routes-v7.php.

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.

How to clear views cache

To clear the scheduled tasks cache, use the php artisan view:cache command.

Laravel will delete the content of storage/views.

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

Other posts to read

Let's review some quick wins that Laravel Collections provide to instantly make your codebase better.

There are multiple ways to check if an array is empty. Let me tell you about each of them and why and when you should use them.

Learn why the "Invalid argument supplied for foreach()" warning happens, and let me show you multiple ways to fix it.

Learning a framework can be overwhelming. Time and practice will make you a master. Here are some best practices to help you toward your goal.

switch, case, and break. What are all these? When should you use it instead of if? What are its pros and cons?

A soft delete in Laravel allows you to prevent mistakes by not removing sensitive data from your database right away.

Learn why the "Using $this when not in object context" error happens, and let me show you the only way to fix.

Learn why and how to fix "Methods with the same name as their class will not be constructors in a future version of PHP" warnings.

Laravel Dropbox Driver is a new storage you can add to your Laravel application and use it for all sorts of things.

Laravel 10 will be released on February 7, 2023. Its development is still ongoing. Let's dive into every relevant new feature we know about already.