In this tutorial you will learn about the How to Clear Cache in Laravel 8 with artisan commands and its application with practical example.
In this tutorial, I’ll show you how to clear cache in laravel 8. We will learn to clear laravel cache of different types example: view cache, application cache, route cache, config cache etc. I’ll show you various laravel artisan commands to clear laravel 8 cache of different types. You will also learn to clear cache on shared hosting without artisan commands.
In Laravel, while developing a laravel application it is very often that changes we made are not reflecting. This is usually happens because of the laravel cache. Laravel provides various caching systems for developing fast loading laravel applications.
In this laravel clear cache example, we will learn to clear cache from command line (CLI), we will see how to clear cache from blade (views), routes,config etc using the command line and artisan command.
Laravel 8 Clear Cache Artisan Commands
Here, we will discuss about various artisans commands used to clear different laravel cache in laravel applications.
How to clear laravel App Cache
To clear laravel application cache use the php artisan cache:clear artisan command as given below :
1 |
php artisan cache:clear |
How to clear laravel route Cache
To clear route cache in laravel use the php artisan route:clear artisan command as given below :
1 |
php artisan route:clear |
How to clear laravel config cache
To clear config cache in laravel use the php artisan config:cache artisan command as given below :
1 |
php artisan config:cache |
How to clear laravel View Cache
To clear compiled view files cache in laravel use the php artisan view:clear artisan command as given below :
1 |
php artisan view:clear |
Laravel Reoptimized Class
Use the following laravel command to Reoptimized Class In laravel :
1 |
php artisan optimize |
Clear Cache On Shared Host Without Artisan Commands
In shared hosting servers typically we don’t have SSH access to the server. In that case, to clear laravel 8 cache we have define routes in our application’s routes/web.php file that invoke the various laravel clear cache commands. This way we can clear Laravel cache by accessing specific routes in the browser.
How to Clear Route Cache from Browser
1 2 3 4 |
Route::get('/route-cache', function() { $exitCode = Artisan::call('route:cache'); return 'Routes cache cleared'; }); |
How to Clear Config Cache from Browser
1 2 3 4 |
Route::get('/config-cache', function() { $exitCode = Artisan::call('config:cache'); return 'Config cache cleared'; }); |
How to Clear Application Cache from Browser
1 2 3 4 |
Route::get('/clear-cache', function() { $exitCode = Artisan::call('cache:clear'); return 'Application cache cleared'; }); |
How to Clear View Cache from Browser
1 2 3 4 |
Route::get('/view-clear', function() { $exitCode = Artisan::call('view:clear'); return 'View cache cleared'; }); |