Magento 2 enable, disable, clean, flush cache using command line

Today we will be discussing various cache command using command line.

Enable all cache using command line

Magento Directory > php bin/magento cache:enable

Result of enabling cache

Changed cache status:

config: 0 -> 1
block_html: 0 -> 1
collections: 0 -> 1
reflection: 0 -> 1
db_ddl: 0 -> 1
eav: 0 -> 1
customer_notification: 0 -> 1
full_page: 0 -> 1
config_integration: 0 -> 1
config_integration_api: 0 -> 1
translate: 0 -> 1
config_webservice: 0 -> 1

Cleaned cache types:
config
block_html
collections
reflection
db_ddl
eav
customer_notification
full_page
config_integration
config_integration_api
translate
config_webservice

To confirm you can check the env.php file in ‘cache_types’ index of array. Also you can execute cli command to confirm status

php bin/magento cache:status

Result of cache status

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

Enable cache of a particular cache type

Magento Directory > php bin/magento cache:enable layout

Result of enabling layout cache

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

Disable cache

Magento Directory > php bin/magento cache:disable

Result of cache disabled

Changed cache status:
config: 1 -> 0
layout: 1 -> 0
block_html: 1 -> 0
collections: 1 -> 0
reflection: 1 -> 0
db_ddl: 1 -> 0
eav: 1 -> 0
customer_notification: 1 -> 0
full_page: 1 -> 0
config_integration: 1 -> 0
config_integration_api: 1 -> 0
translate: 1 -> 0
config_webservice: 1 -> 0

Disable cache for specific type

php bin/magento cache:disable CACHE_TYPE

Example:

php bin/magento cache:disable layout

cache clean and flush

Cache clean and flush are two ways to remove cache in Magento, the difference in them is

1. cache:clean will remove cache by tags i.e, only cache that are maintained by proper tags are removed while in case of cache:flush all cache will be removed i.e, sometimes cache is not maintained in proper tags, that cache will be removed by cache:flush not by cache:clean.
2. Also when we use some third party plugin to manage cache such as Redis also maintain its cache and if we have maintained Redis and Magento cache at same place(not recommended) then cache:flush will remove that also, thus cache:clean is used at that instance.

clean the Magento cache

Magento Directory > php bin/magento cache:clean

Result of cache clean

Cleaned cache types:
config
layout
block_html
collections
reflection
db_ddl
eav
customer_notification
full_page
config_integration
config_integration_api
translate
config_webservice

Flush the Magento cache

Magento Directory > php bin/magento cache:flush

Result of cache clean

Flushed cache types:
config
layout
block_html
collections
reflection
db_ddl
eav
customer_notification
full_page
config_integration
config_integration_api
translate
config_webservice

Leave a Comment.