
2 minutes read
8 ways to clear Laravel's cache
Introduction + TL;DR
When in doubt, clear the cache. To instantly clear all Laravel caches (routes, config, events, views, and more), run:
php artisan optimize:clear
This command clears these items:
- Configuration cache
- Bootstrap files cache
- Auto-discovered events cache
- Application cache
- Routes cache
- Views cache
Heads up: Ideal for development, but avoid running frequently in production—Laravel needs time to rebuild caches.
Clear individual Laravel caches
Do you prefer more granular control? Laravel has commands for that too.
Application cache
Clear the entire app cache:
php artisan cache:clear
Clear a single entry:
php artisan cache:forget <key> [store]
Clear caches by tag (default store only; specify --store
if needed):
php artisan cache:clear --tags tag1,tag2
Programmatically clearing cache
Use Laravel’s Cache
facade:
use Illuminate\Support\Facades\Cache; Cache::forget('key'); Cache::flush();
Or the simpler helper:
cache()->forget('key'); cache()->flush();
Config cache
Clear configuration cache easily:
php artisan config:clear
Laravel deletes bootstrap/cache/config.php
, forcing fresh configurations.
Learn more about config caching.
Event cache
Clear cached event listeners:
php artisan event:clear
Useful after adding new listeners/events.
Learn more about event caching.
Routes cache
Clear routes quickly:
php artisan route:clear
Laravel deletes bootstrap/cache/routes-v7.php
, applying updates immediately.
Learn more about route caching.
Scheduled tasks cache
Clear scheduled tasks cache:
php artisan schedule:clear-cache
Caution: Only use in production when troubleshooting task overlaps. Learn more.
Views cache
Clear cached views instantly:
php artisan view:clear
Laravel empties storage/framework/views
, forcing regeneration.
Learn more about optimizing views.
Bonus: Completely disable caching
Disable caching entirely by editing .env
:
CACHE_DRIVER=null
Useful for testing or debugging.
Important: When NOT to clear cache
- Production deploys: Strategically cache (
config:cache
,route:cache
) instead. - Routine cron jobs: Frequent clearing slows your app down.
Clear caches deliberately during maintenance or deploy windows.
Did you like this article? Then, keep learning:
- Fix common Laravel errors related to cache and transactions
- Learn to fix the frequent "419 Page Expired" error in Laravel
- Go deeper with asynchronous caching techniques in Laravel
- Discover how to clear Laravel's config files and middleware in Laravel 11
- Learn how to create Laravel Factories using ChatGPT for faster testing setup
- Understand how Laravel works internally to enhance caching and performance knowledge
- Explore best practices for Laravel including cache usage for 2024
- Discover how to monitor your Laravel apps including cache-related metrics
- Learn about Artisan, Laravel's command interface that includes cache commands
- Explore flexible caching strategies to balance freshness and performance
2 comments
done
That's exactly what this article is meant for, haha!