Caching Routes, Config, and Views

Laravel supports caching several parts of an application's bootstrap process, which noticeably reduces overhead on every request in production.

Caching Configuration

php artisan config:cache

This combines all config files into a single cached file, avoiding the cost of loading and merging them on every request. Important: once cached, calls to env() outside config files will no longer work correctly.

Caching Routes

php artisan route:cache

Useful for applications with a large number of routes, since it avoids re-parsing every route definition on each request. Note that routes using closures cannot be cached this way.

Caching Views

php artisan view:cache

Pre-compiles all Blade templates so the first request after deploy doesn't pay the compilation cost.

Clearing All Caches

php artisan optimize:clear

Run this before re-caching after any deploy, so stale cached config or routes don't linger.

These caching commands are one part of a broader set of techniques for keeping a Laravel application fast, which the final topic looks at more widely.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course