DEV Community

Cover image for How to Clear Cache In Laravel 8
Suresh Ramani
Suresh Ramani

Posted on • Originally published at techvblogs.com

How to Clear Cache In Laravel 8

In this tutorial, We are going to learn how to clear route cache, laravel application cache, config cache, view cache and reoptimize class in a Laravel 8 application.

In Laravel, while developing a laravel application it is very often that changes we made are not reflected. This is usually happening because of the laravel cache. Laravel provides various caching systems for developing fast-loading laravel applications.

We will also learn how to remove cache in laravel with artisan command.

1. Laravel Cache Clear using Commands Line

  1. Laravel Clear Route Cache
  2. Laravel Clear App Cache
  3. Laravel Clear Config Cache
  4. Laravel Clear View Cache
  5. Laravel Clear Cache using Reoptimized Class

Clear Route Cache

Use the below command and clear your routes cache:

php artisan route:cache
Enter fullscreen mode Exit fullscreen mode

Clear Application Cache

Use the below command and clear your application cache like session cache, cookies cache:

php artisan cache:clear
Enter fullscreen mode Exit fullscreen mode

Clear Config Cache

Use the below command and clear your config cache:

php artisan config:clear
Enter fullscreen mode Exit fullscreen mode

Clear View Cache

Use the below command and clear your view (blade) cache:

php artisan view:clear
Enter fullscreen mode Exit fullscreen mode

Clear Cache using Reoptimized Class

php artisan optimize:clear
Enter fullscreen mode Exit fullscreen mode

2. Laravel Cache Clear using Artisan Command

In shared hosting servers typically we don’t have SSH access to the server. In that case, to clear Laravel cache we have to define routes in our application’s routes/web.php file that invoke the various Laravel clear cache commands. This way we can clear the Laravel cache by accessing specific routes in the browser.

//Clear route cache
 Route::get('/route-cache', function() {
     \Artisan::call('route:cache');
     return 'Routes cache cleared';
 });

 //Clear config cache
 Route::get('/config-cache', function() {
     \Artisan::call('config:cache');
     return 'Config cache cleared';
 }); 

 // Clear application cache
 Route::get('/clear-cache', function() {
     \Artisan::call('cache:clear');
     return 'Application cache cleared';
 });

 // Clear view cache
 Route::get('/view-clear', function() {
     \Artisan::call('view:clear');
     return 'View cache cleared';
 });

 // Clear cache using reoptimized class
 Route::get('/optimize-clear', function() {
     \Artisan::call('optimize:clear');
     return 'View cache cleared';
 });
Enter fullscreen mode Exit fullscreen mode

Thank you for reading this blog.

Top comments (0)