How to Clear Cache in Laravel Application Using Artisan Command

Cyber Hacking & Security International National Science & Technology

Laravel is a PHP framework that is used for building web applications. It is based on the popular Symphony framework and follows the MVC (Model–View–Controller) Pattern. Most of Frameworks and Applications use cache feature to store frequently usage files in a temporary storage folder and serve them faster on requests. Caching reduces the request processing time to increase application performance. In this article you will learn how to clear the cache of your Laravel Web Application. You can clear the Laravel App cache by using a commandline interface or by adding the PHP code to the application’s  “Routes/Web.Php” file. I am teaching you both methods to clear laravel cache.

IF YOU WANT TO CLEAR CACHE USING COMMNADLINE THEN OPEN YOUR TERMINAL AND NAVIGATE TO THE LARAVEL APPLICATION’S FOLDER AND EXECUTE BELOW COMMANDS

To Clear Laravel Application Cache, Run The Following Artisan Command:

php artisan cache:clear

To Clear Route Cache, Run The Following Artisan Command:

php artisan route:clear

To Clear The Config Cache, Run The Following Artisan Command:

php artisan config:clear

To Clear The View Cache, Run The Following Artisan Command:

php artisan view:clear

To Clear The Cache Using Re-Optimize Class, Run The Following Artisan Command:

php artisan optimize:clear

 

IF YOU WANT TO CLEAR THE CACHE USING PHP CODING VIA WEB BROWSER WITHOUT USING ARTISAN COMMANDS THEN FOLLOW BELOW METHOD:

Most Of Hosting Companies Dont Allow Shared Hosting Customers Access SSH Console. On This Condition You Need To Make Changes In Your Application’s “Routes/Web.Php” File That Will Execute Laravel Clear Cache Commands. By Doing This Coding You Can Clear The Laravel Cache By Accessing Specific Routes From The Web 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’;
});

Thanks for Reading

Writer & Editor: Ravikant Upadhyay (+91.8085883358)
(Entrepreneur, Programmer, Trader, Investor, Writer, Reporter, Thinker, Mentor, Astrophile)

Cyber Hacking & Security International National Science & Technology
Keywords: Artisan Command, Clear Cache Laravel, Laravel Cache, MVC, Without Artisan,

Similar Posts