How to Clear Cache in Laravel
Laravel caches various things like configurations, routes, views, and application data to improve performance. Sometimes, you need to clear the cache during development or troubleshooting. Here’s how you can do it:
1. Clear Application Cache
To clear the application cache, run:
š This will remove all cached data stored using cache()
.
2. Clear Route Cache
If you made changes to your routes and want to refresh them, use:
š This will remove the cached route file (bootstrap/cache/routes.php
).
š If you want to re-cache routes, run:
3. Clear Configuration Cache
Laravel caches configuration files to speed up performance. To clear it, run:
š This removes the cached config file (bootstrap/cache/config.php
).
š To re-cache configuration files, run:
4. Clear View Cache
If Blade templates are not updating, clear the view cache:
š This deletes compiled Blade views from storage/framework/views/
.
š To recompile views, simply refresh your Laravel app in the browser.
5. Clear Event Cache
If you're using event caching, you can clear it with:
š To re-cache events, run:
6. Clear All Caches in One Command
To clear everything at once, use:
š This clears cache, route cache, view cache, config cache, and compiled services.
7. Clear Cache from the Browser (Without SSH)
If you don't have SSH access, you can add this route in web.php
and visit it in the browser:
š Now visit yourwebsite.com/clear-cache
to clear the cache.
8. Clear Specific Cache Keys (Application Cache)
If you want to clear a specific cache entry, use:
To clear all cache data stored via the cache()
helper:
Conclusion
Cache Type | Command |
---|---|
Application Cache | php artisan cache:clear |
Route Cache | php artisan route:clear |
Config Cache | php artisan config:clear |
View Cache | php artisan view:clear |
Event Cache | php artisan event:clear |
Clear Everything | php artisan optimize:clear |
Now your Laravel cache is cleared! š Let me know if you need more help. š