How to clean the Laravel cache

Clean Laravel cache with an example: how to use artisan & config commands to quickly clear laravel's cache for improved performance.

Caching plays an important part in improving the performance of any Laravel application. When you use Laravel, the framework will store cached data in the application's storage/framework/cache directory. If the application's codebase or configuration changes, this cached data needs to be refreshed.

Fortunately, Laravel provides a few easy ways to clear the cache. Below are two methods for clearing the cache in a Laravel application.

1. Clearing Cache using Artisan Commands

The easiest way to clear the cache in Laravel is by using the Artisan command-line tool. To clear the application cache, run the following command:

php artisan cache:clear

This command will clear the application cache and also delete any cached views. This is a very quick and easy way to clear the cache.

2. Clearing Cache in the Background

If you don't want to manually run the Artisan command to clear the cache, you can also configure Laravel to do this automatically in the background. To do this, you need to open the config/cache.php file and set the following:

'clear_cache_listener' => true,

Once you have set this option to true, Laravel will automatically clear the application cache and delete any cached views whenever a new version of your codebase is deployed.

Clearing the cache in Laravel is a quick and easy process. By using the Artisan command or configuring the application to do it in the background, you can make sure that the cached data is always up-to-date.

Answers (0)