TechvBlogs
Published in

TechvBlogs

How to Clear Cache In Laravel 8

Oct 26, 2021, Originally published at techvblogs.com ・2 min read

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

  • Laravel Clear Route Cache
  • Laravel Clear App Cache
  • Laravel Clear Config Cache
  • Laravel Clear View Cache
  • Laravel Clear Cache using Reoptimized Class

Clear Route Cache

Use the below command and clear your routes cache:

php artisan route:cache

Clear Application Cache

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

php artisan cache:clear

Clear Config Cache

Use the below command and clear your config cache:

php artisan config:clear

Clear View Cache

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

php artisan view:clear

Clear Cache using Reoptimized Class

php artisan optimize:clear

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';
});

Thank you for reading this blog.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Smit Pipaliya

Smit Pipaliya

I am Senior Developer at ServerAvatar Technology.