Laravel uses a variety of caching systems to keep applications running smoothly. These caches include route caching, view caching, config caching, query caching and others. When we change something in a Laravel application, sometimes it doesn’t work because of caching. That’s why we have to clear cash. Here is a list of Laravel cache and how to clear them:
1. Application Cache
The application cache stores the temporary data like query, search result, setting and others.
Clear the application cache:
php artisan cache:clear
2. Route Cache
Laravel caches all registered routes to reduce processing time.
Clear the route cache:
php artisan route:clear
Rebuild the route cache:
php artisan route:cache
3. View Cache
Laravel compiles Blade templates into plain PHP files for better performance. These compiled files are cached.
Clear the view cache:
php artisan view:clear
4. Config Cache
Configuration files are cached to better performance, especially in live server applications.
Clear the config cache:
php artisan config:clear
4. Config Cache
Configuration files are cached to better performance, especially in live server applications.
Clear the config cache:
php artisan config:clear
Rebuild the config cache:
php artisan config:cache
5. Event Cache
Laravel also caches event listeners.
Clear the event cache:
php artisan event:clear
Rebuild the config cache:
php artisan event:cache
6. Compiled Services and Packages
Laravel compiles its services and packages for quicker loading.
Clear the compiled services and packages cache:
php artisan clear-compiled
7. Query Cache
If you’re caching database queries, you can manually flush the query cache by invalidating it from the database connection or cache store.
Manually clear the query cache (if using Redis):
redis-cli flushall
8. Custom Cache
If you have custom caches (like storing user sessions or other application-specific data), you need to clear them programmatically using the code from below
Cache::forget()
You can also use
Cache::flush()