How to Clear Cache In Laravel 8 - TechvBlogs

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 reoptimized class in a Laravel 8 application using artisan command-line interface.


Suresh Ramani - Author - TechvBlogs
Suresh Ramani
 

2 years ago

TechvBlogs - Google News

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

Read Also: Laravel 8 Import Export Excel & CSV File Example

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

Read Also: Upload Files and Images with Validation in Laravel

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.

Read Also: How to Install Git On Ubuntu 20.04

If you want to manage your VPS / VM Server without touching the command line go and  Checkout this linkServerAvatar allows you to quickly set up WordPress or Custom PHP websites on VPS / VM in a  matter of minutes.  You can host multiple websites on a single VPS / VM, configure SSL certificates, and monitor the health of your server without ever touching the command line interface.

If you have any queries or doubts about this topic please feel free to contact us. We will try to reach you.

Comments (0)

Comment


Note: All Input Fields are required.