Table Of Contents
- Quick Fix: The Nuclear Option
- The Complete Cache Management Toolkit
- Deployment and Production Commands
Quick Fix: The Nuclear Option
When your Laravel app is acting weird after changes, clear all caches at once:
# Clear everything (route, config, view, application cache)
php artisan optimize:clear
# Individual cache clearing commands
php artisan cache:clear # Application cache
php artisan config:clear # Configuration cache
php artisan route:clear # Route cache
php artisan view:clear # Compiled views
php artisan event:clear # Event cache (Laravel 9+)
The Complete Cache Management Toolkit
Different caches serve different purposes. Here's when to clear each one:
# After .env changes or config modifications
php artisan config:clear
php artisan config:cache # Rebuild config cache
# After route changes (routes/web.php, routes/api.php)
php artisan route:clear
php artisan route:cache # Rebuild route cache
# After Blade template changes in production
php artisan view:clear
# Clear application cache (Cache::put(), session data)
php artisan cache:clear
# Clear specific cache stores
php artisan cache:clear --store=redis
php artisan cache:clear --tags=users,posts
# One command to rule them all
php artisan optimize:clear && php artisan optimize
Deployment and Production Commands
For deployment scripts, use this sequence to avoid "Class not found" or "Route not defined" errors:
# Standard deployment cache refresh
php artisan optimize:clear
php artisan optimize
# Or the manual approach
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear
# Then rebuild caches
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Laravel 11+ includes event caching
php artisan event:cache
Bonus commands for debugging cache issues:
# See what's cached
php artisan route:list # Show all cached routes
php artisan config:show # Show cached config (Laravel 9+)
# Debug cache drivers
php artisan tinker
>>> Cache::getStore() # See current cache driver
>>> Cache::flush() # Alternative to cache:clear
The optimize:clear
command is your best friend during development. It clears all Laravel caches in one go, perfect for when you're not sure which cache is causing issues. For production deployments, always clear caches before rebuilding them to avoid stale data mixing with new configurations.
Related: Laravel Collections: Beyond Basic Array Operations | Laravel Events and Listeners: Building Decoupled Applications | Building Multi-tenant Applications with Laravel: A Comprehensive Guide | Caching: From Database Overload to Lightning-Fast Responses | Creating Custom Laravel Artisan Commands: Advanced Techniques
Add Comment
No comments yet. Be the first to comment!