How to clear cache in Laravel - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to clear cache in Laravel
=============================

### [\#Laravel](https://rocketeersapp.com/knowledge/laravel)

Laravel uses caching for a lot of parts of the framework, here's how you can clear all of them.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on February 15, 2024 · 2 minute read

1. [How to clear all caches at once](#content-how-to-clear-all-caches-at-once)
2. [Application cache](#content-application-cache)
3. [Framework cache](#content-framework-cache)
4. [Config cache](#content-config-cache)
5. [Events cache](#content-events-cache)
6. [Routes cache](#content-routes-cache)
7. [Views cache](#content-views-cache)
8. [Use Laravel without cache](#content-use-laravel-without-cache)
9. [Array or null cache driver](#content-array-or-null-cache-driver)

[\#](#content-how-to-clear-all-caches-at-once "Permalink")How to clear all caches at once
-----------------------------------------------------------------------------------------

To clear all caches at once, Laravel has a specific optimize command that can clear every major cache in the application. This includes the configured cache driver, the events, views, route, config and bootstrap files:

 ```
php artisan optimize:clear

```

[\#](#content-application-cache "Permalink")Application cache
-------------------------------------------------------------

Laravel has versatile cache functionalities baked in the framework. It can handle multiple cache stores like file based, using a database (MySQL, PotgreSQL, SQLite, Redis) or specific software like memcached.

Using the command line you can clear the default configured cache with:

 ```
php artisan cache:clear

```

But you can also define another store that's not the default, but is configurred and used within your app:

 ```
php artisan cache:clear file # other stores are: apc, array, database, file, memcached, redis, dynamodb, octane

```

Clearing the cache within application code is possible using:

 ```
use Illuminate\Support\Facades\Cache;

Cache::flush(); # clear default cache
Cache::store('memcached')->flush(); # clear cache for 'memcached' store

```

[\#](#content-framework-cache "Permalink")Framework cache
---------------------------------------------------------

Laravel has multiple ways to improve its performance by caching framework specific functionality. Here are all caches Laravel uses to bootstrap the framework as quickly as possible:

### [\#](#content-config-cache "Permalink")Config cache

Using `php artisan config:cache` during deployments, Laravel can optimize config files and make them as static as possble to quickly load the config on each request. This also means you cannot update config dynamically anymore using the helper `config([])`. You can clear the config cache using:

 ```
php artisan config:clear

```

### [\#](#content-events-cache "Permalink")Events cache

Using `php artisan events:cache` when deploying, Laravel can collect all event files upfront, which makes loading of a lot of scatered events inside your application much faster.

 ```
php artisan events:clear

```

### [\#](#content-routes-cache "Permalink")Routes cache

To further optimize performance, you can use `php artisan routes:cache` to deploy your Laravel app with an optimized routes cache. This collects all registered routes and creates a static cache to match every route as fast as possible.

Clearing the routes cache:

 ```
php artisan routes:clear

```

### [\#](#content-views-cache "Permalink")Views cache

Laravel compiles the Blade syntax to PHP code when executing the views for rendering it in your application. This cache is stored in `storage/framework/views` and contains all Blade views compiled to PHP files.

Clearing this cache can be done with:

 ```
php artisan views:clear

```

[\#](#content-use-laravel-without-cache "Permalink")Use Laravel without cache
-----------------------------------------------------------------------------

[\#](#content-array-or-null-cache-driver "Permalink")Array or null cache driver
-------------------------------------------------------------------------------

To really have no cache at all, you can configure `array` or `null` as cache driver. So this means you have no store at all, only during the runtime of a request the cache will work. After each request the cache will be empty again.

 ```
CACHE_DRIVER=null # or "array"

```

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Laravel](https://rocketeersapp.com/knowledge/laravel)

- [How to use different PHP versions with Laravel Valet](https://rocketeersapp.com/knowledge/different-php-versions-laravel-valet)
- [Disable cookies in Laravel](https://rocketeersapp.com/knowledge/disable-cookies-in-laravel)
- [Logging in Laravel](https://rocketeersapp.com/knowledge/laravel-logging)
- [How to check which Laravel version of your app is using](https://rocketeersapp.com/knowledge/check-laravel-version)
- [Disable CSRF in Laravel](https://rocketeersapp.com/knowledge/disable-csrf-in-laravel)
- [Creating an encrypted cookie value in Laravel](https://rocketeersapp.com/knowledge/creating-an-encrypted-cookie-value-in-laravel)

 [View all 19 articles →](https://rocketeersapp.com/knowledge/laravel)
