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.
- 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 artisan config:clear
- Configuration Clear and Cache again: If you want to clear the configuration cache and again cache it newly, there is a command
php artisan config:cache
- 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 artisan route:clear
- Route Clear and Cache again: If you want to clear the Route cache and again cache it newly, there is a command
php artisan route:cache
This command will clear route cache and at the same time it will create new route cache
- 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 artisan view:clear
If you want to clear the view cache and again cache it newly, then the command will be
php artisan view:cache
- 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 artisan event:clear
If you want to clear the event cache and again cache it again, then the command will be
php artisan event:cache
- 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 artisan cache:clear
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.