Cache is used to improve the performance of web application using caching the views templates, queries, CSS, JavaScript etc. Cache improves the performance by serving the cached pages and improves the speed of website but sometime develops face issues like they change something in Laravel application but it does not reflect. so in this article we are going g to learn to clear the cache of Laravel application.
There is 2 ways to clear the cache in laravel
- Using the command line
- Using the browser(If you do not have rights to run artisan command from terminal)
Clear cache from command line in Laravel
To clear from command line or terminal you need to ssh into the server and navigate to our project.
There is 4 types of cache in Laravel
- Application cache
- Route cache
- Configuration cache
- View Cache
1. Clear application cache in laravel
Run the below command to clear application cache
php artisan cache:clear
2. Clear route cache in laravel
Run the below command to clear route cache
php artisan route:clear
3. Clear Configuration cache in laravel
Run the below command to clear application cache
php artisan config:clear
4. Clear views cache in laravel
Run the below command to clear application cache
php artisan views:clear
Clear cache of Laravel using browser
Sometime or we can say on shared hosting we are unable to access the ssh or terminal then we are unable to run these above commands. so, Laravel also support to call the artisan command from our application code and we can run them by hitting the URL in browser.
To clear the cache from browser we need to create a route in routes/web.php
and then define the below code
Route::get('/clear-cache', function() {
Artisan::call('cache:clear');
Artisan::call('config:clear');
Artisan::call('views:clear');
return "Cache is removed";
});