Laravel how to clean a cache

Laravel caching made easy: learn how to clear cache using artisan command, with example.

Cleaning a Laravel Cache

Caches can be a huge help when it comes to speeding up your Laravel application. However, sometimes you need to clear the cache in order to make sure your changes take effect. Here's a quick guide on how to clear the cache in Laravel.

The first step is to get the cache manager. You can do this by using the following command in the terminal:

$cacheManager = app('cache');

Once you have the cache manager, you can clear the entire cache using the following command:

$cacheManager->flush();

If you want to clear just a single cache, you can do that as well. For example, to clear the application cache, you can use the following command:

$cacheManager->forget('application');

It's also possible to clear multiple caches at once. To do this, you can use the following command:

$cacheManager->forget(['application', 'view']);

Finally, you can also clear the cache using artisan commands. To clear the application cache, you can use the following command:

php artisan cache:clear

And to clear the view cache, you can use the following command:

php artisan view:clear

That's it! Clearing the Laravel cache is a quick and easy process. With just a few commands, you can make sure that your application is running smoothly and that your changes are taking effect.

Answers (0)