Ramesh Thapa

Sharing my personal opinion and notes

How to clear cache in laravel?

How to clear cache in laravel?

When you start develop website or application using laravel framework, then must know clear cache file. To clear cache in laravel, you can do it by two methods. Both types of method are verified in laravel 5.
1. By clearing cache from browser
2. By ssh method.

Clearing cache from browser:

For this you must add certain line of code in your laravel application. In your routes/web.php file of Laravel application you can put following code. Then access this URL in the browser to clear the cache of Laravel application. This is used when shared hosting provider does not provide shell access enabled. It is also useful for the user or owner of laravel application if he had not technical knowledge. You can provide him just laravel cache url.

Route::get(‘/clear-cache’, function() {
Artisan::call(‘cache:clear’);
return “Cache is cleared successfully !”;
});

 

Clearing cache in laravel from terminal

For clearing cache from terminal your hosting provider must enabled shell access on your sites or application. After you login or go to terminal of laravel application you can use following command to clear cache in larvael.

1. Clear cache of view file
When you need to cache view files like js, css, this types of cache is used. You can do it by following command.

$php artisan view:clear

 

2. Clear application cache
For clearing application cache you need use to following command in terminal.

$php artisan cache:clear

3. Clear route cache
For clearing route (url) cache you need following command

$php artisan route:clear

If your application is exclusively using controller based routes, you should take advantage of Laravel’s route cache. Using the route cache will drastically decrease the amount of time it takes to register all of your application’s routes.

To generate a route cache, use following  Artisan command:

php artisan route:cache

4. Clear configuration cache
For clearing laravel application config cache, you need to use following command.

$php artisan config:clear

Leave comment

Your email address will not be published. Required fields are marked with *.