Tinkerwell 4 is out now! See what's new or buy now.
Tinkerwell background image
Tinkerwell Logo Tinkerwell
Go back to Blog

Laravel caches and all ways to clear them

Laravel has different caches for different parts of your application and so there are multiple ways to clear the Laravel cache.

Before you actually clear your cache, check out Tinkerwell. Tinkerwell will be your favorite compagnion to your IDE and as a Laravel developer, you'll use it every day.

Application cache
#

The application cache is the primary cache in Laravel. It stores everything that you manually cache in your application. You can clear only specific elements of the cache if you use tags or different cache stores. The easiest way to clear the Laravel cache is via artisan:

Clear Laravel cache via artisan command
#

php artisan cache:clear

If you use multiple caches and you want to clear a specific store, you can pass this as a parameter to the command:

php artisan cache:clear --store=redis

You can clear cached items with specific tags with the command:

php artisan cache:clear --tags=tag1,tag2

Clear Laravel cache programmatically
#

Removing items from the cache programmatically is as easy as clearing the cache via the artisan command. In addition, you can use the cache facade to access the cache or use the cache helper.

Cache::flush()
cache()->flush()

Clearing cached items with the tag awesome-tag is as easy as purging a specific cache store:

cache()->store('redis')->tags('awesome-tag')->flush()

Whenever I want to check if there is an item in the cache or remove it from the cache, I start Tinkerwell and run the commands above.

View cache
#

Another part of the application that has a cache is the view cache. The view cache stores rendered Blade templates to speed up your application. You can manually render all views to increase the performance by using the artisan command for it:

php artisan view:cache

If you use this optimization, you have to clear the cache if you deploy new code, otherwise, Laravel uses your old views and you'll try to debug this forever. You can clear the view cache of Laravel with the command:

php artisan view:clear

Config cache
#

Laravel recommends caching your configuration files so that the application doesn't need to go through all config files while it bootstraps the framework.

You can combine all config files into one large file and optimize the performance with the command:

php artisan config:cache

Make sure to clear this cache if you change a configuration, for example, during a production deployment process:

php artisan config:clear

Event cache
#

When running in production, caching the Events and their Listeners allows for efficient event handling. Laravel recommends to cache events and listeneners during your deployment process – and this means that you have to clear the event cache too.

To cache events and listeners, run the event:cache command during your deployment:

php artisan event:cache

The event:cache command automatically clears all event caches, but if you have to run it manually, you can do it like this:

php artisan event:clear

Route cache
#

The route cache is an additional performance cache that you only want to use in production and as part of your deployment process. Caching your routes drastically decreases the amount of time to register your application's routes. You can cache the routes via:

php artisan route:cache

In case you change a route or tried the cache command during development, you have to clear the route cache or your application won't find new routes. You clear the route cache with the command:

php artisan route:clear
Jess Archer, Laravel Core team member
“Tinkerwell is the fastest way to test an idea or debug an application. It just keeps getting better and better!”

Jess Archer

Laravel Core team member

André Breia, Technical Lead
“Tinkerwell is the perfect companion for every developer. It helps with debugging and quickly testing logic. It increases productivity and it keeps getting better and better!”
André Breia

Technical Lead

Tinkerwell: The PHP Scratchpad

The must-have companion to your favorite IDE. Quickly iterate on PHP code within the context of your web application.

Buy now Learn more