How to Clear Cache in Laravel

How to Clear Cache in Laravel

How to Clear Cache in Laravel

Hello folks, in this short tutorial we will learn how to clear cache in Laravel and many other things related to Caching. Lets jump into it.

We will learn about configuration cache, view cache, route cache and many other things. There are several types of cache. Lets discuss one by one and also learn how to clean these.

  1. Configuration cache: In Laravel, configuration cache combines all the configuration in a single cached file so that loading can be improved. Sometimes any configuration value changes doesn’t affect because it is cached. That’s when you need to clear configuration cache cleared. For that, you have to run:

    [php]php artisan config:clear[/php]

  2. Configuration Clear and Cache again: If you want to clear the configuration cache and again cache it newly, there is a command

    [php]php artisan config:cache[/php]

  3. Route Cache: Just like Configuration Cache, Route Cache works same. It caches the routes and saves time. If you add a route, clear the route cache by running below command.

    [php]php artisan route:clear[/php]

  4. Route Clear and Cache again: If you want to clear the Route cache and again cache it newly, there is a command

    [php]php artisan route:cache[/php]

    This command will clear route cache and at the same time it will create new route cache

  5. View Cache: View Cache compile a view file as a compiled view file which basically imrpoves the speed of loading view. If you change somethins and want to clear the compiled view file, you have to run

    [php] php artisan view:clear[/php]

    If you want to clear the view cache and again cache it newly, then the command will be

    [php] php artisan view:cache [/php]

  6. Event Cache: In Laravel we use event to listen to those events and perform tasks based on that event. It is a good practice to cache the events to run faster the Laravel Application. All you have to run:

    [php] php artisan event:clear[/php]

    If you want to clear the event cache and again cache it again, then the command will be

    [php] php artisan event:cache [/php]

  7. Application Cache: Application Cache is used for storing several types of data in cache folder, which is used to improve the speed and performance of the application. But if you want to clean the cache, you have to run:

    [php] php artisan cache:clear [/php]

    Also, Facade is available Cache::flush(); 

 

That’s all for today. Last thing is, caching is so important in live application. By caching, it helps a lot to the application and also a release for the server. But in development period, caching maybe a pain . But if we know all the caching and clearing cache command, it is lot more easier.

Editorial Staff

A Learner and trying to share what I learned!