Laravel Clear Cache Using Artisan Command

Laravel Clear Cache Using Artisan Command

If you are making a lot of changes to your views and configurations then you might have encountered the problem I can’t see my changes, you should run the Laravel clear cache command in your terminal.

When your application is in production mode you should try to leverage the cache as much as you can, but if your application is in the development mode then you can face some issues regarding the actual results you are looking for. This is due to some part of your application is served by the cache.

In this post, we will look at how we can use Laravel clear cache commands which you run in your terminal and what are the benefits of them.

Laravel Artisan

Laravel Artisan is a command line interface (CLI) which allows you to manage your application by running few commands. This interface also helps you to clear the cache of your application using the terminal.

Laravel Artisan also provides various commands which help you to generate various components of the Laravel’s framework. If you are developing the Laravel application for some time, you might already know the commands offered by Laravel Artisan’s CLI.

You can view all commands offered by Laravel Artisan using the below command:

php artisan list

Laravel Config Cache

Any Laravel application is based on the many configuration files which come with the Laravel’s installation and reside in config/ folder. Imagine, if you are using a modular approach in your application (As I do) then you will have to define a config file for each module. As soon as your application grows, your application will be heavily relying on Laravel’s configurations which will at some point slow down your application.

Laravel framework provides an easy mechanism to combine all those configuration files into one file using the below artisan command:

php artisan config:cache

As soon as you will run the above command, you will see a significant improvement in your application’s performance.

Clearning Laravel’s Configuration Cache

If you study the Laravel’s framework, you will find out that at some places Laravel heavily use the configuration files to get certain values like database credentials. Let’s assume your application was running on the current server with the current configuration values.

For performance reasons, you have to move your application to a different server, in that case, you have to update all the configuration values.

What about the configuration values stored in the cache?

In this case, you have to clear the cache so that Laravel uses the current values for the configuration. Laravel provides a simple artisan command to clear all cached values. To clear cached values use the below command in the terminal.

php artisan config:clear

Clearning Laravel’s Application Cache

Sometimes simply clearing application configuration files is not the solution. There is always a possibility that inconsistency can exist in your code base or application itself, this is where you have to clear the whole application’s cache.

In such a situation, all you have to do is clear cache on the application level using below artisan command:

php artisan cache:clear

Other Laravel Cache Clear Commands

Let’s list down all important commands which you can use to clear cache for a specific section.

Laravel Cache Clear

To clear the application’s cache on application level run the below command:

php artisan cache:clear

Laravel Clear Route Cache

To clear all the cached routes of your application run the below command:

php artisan route:cache

Laravel Clear View Cache

If you have made any changes to your views and can’t see the changes or any views related error which you are one hundred percent sure it’s fixed, then it might be an indication that you have to clear the cached views.

Run below command in the terminal to clear all cached views:

php artisan view:clear

Conclusion

In this short post, we looked at how we can clear the cache of the Laravel application, which not only will fix any errors you are facing also will boost the performance of your application. To learn more about how you can improve the Laravel’s application performance check our post on Laravel Performance Tips.

If you have any question or suggestions, please leave them in the comments box below.

One comment on “Laravel Clear Cache Using Artisan Command

Leave a Reply

Your email address will not be published. Required fields are marked *

*

When sharing a code snippet please wrap you code with pre tag and add a class code-block to it like below.
<pre class="code-block">you code here</pre>

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.