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.
Top comments (0)