Magento 2: Enable/Disable/Clear Cache (Clean/Flush) via Command Line

This article shows how you can clear Magento 2 cache using command line. In my previous article, I have listed out all the command line tools that can be used in Magento 2. This article specifically shows about commands to clear Magento 2 cache.

Check Cache Status

First of all, let’s see what is the status of different cache types in our Magento store. For that, you can use the following command:


php bin/magento cache:status

This will show something like below:

Current status:
config: 1
layout: 1
block_html: 1
collections: 1
reflection: 1
db_ddl: 1
eav: 1
customer_notification: 1
full_page: 1
config_integration: 1
config_integration_api: 1
translate: 1
config_webservice: 1

Here, config, layout, block_html, etc. are all “cache types”. The number “1” assigned to each cache type indicates that they are all enabled. If they are assigned number “0” then that indicates that the cache types are disabled.

1 = enabled
0 = disabled

Enable/Disable Cache Types

Disable Individual Cache Types

From above result, we can see that all of the cache types are enabled. Let’s disable some of the cache types.

Let’s disable layout & block_html cache types.


php bin/magento cache:disable layout block_html

Running this command will output something like this:

Changed cache status:
layout: 1 -> 0
block_html: 1 -> 0

Now, let’s see the cache status with the following command:


php bin/magento cache:status

This will output the following:

Current status:
config: 1
layout: 0
block_html: 0
collections: 1
reflection: 1
db_ddl: 1
eav: 1
customer_notification: 1
full_page: 1
config_integration: 1
config_integration_api: 1
translate: 1
config_webservice: 1

Number 0 assigned to layout and block_html cache types indicate that those cache types are disabled.

Enable Individual Cache Types

Let’s enable the layout & block_html cache types.


php bin/magento cache:enable layout block_html

Running this command will output something like this:

Changed cache status:
layout: 0 -> 1
block_html: 0 -> 1
Cleaned cache types:
layout
block_html

Disable All Cache Types

Using the cache:disable command without specifying any cache type will disable all cache types.


php bin/magento cache:disable

Enable All Cache Types

Using the cache:enable command without specifying any cache type will enable all cache types.


php bin/magento cache:enable

Clear Cache

There are two commands to clear cache in Magento 2.


cache:clean & cache:flush

Clean command is used to clean Magento cache types only. It only cleans cache that is related to Magento. It doesn’t affect cache created by other process and application.

Flush command is used to delete the entire cache storage of Magento 2. The cache storage can contain Magento cache types and cache files of other processes and applications as well. So, using flush command will delete them all.

It’s always a good idea to use Clean command to clear the cache. If the clean command doesn’t solve your cache issue then only use the Flush command.

Clear Individual Cache Types

Let’s clear layout & block_html cache types.


php bin/magento cache:clean layout block_html

Running this command will output something like this:

Cleaned cache types:
layout
block_html

Clear All Cache Types

Using the cache:clean command without specifying any cache type will clear all cache types.


php bin/magento cache:clean

Flush All Cache Types

Usage of cache:flush command is similar to the cache:clean command.


php bin/magento cache:flush

Hope this helps. Thanks.