Manage cache Magento 2 using command line – In Magento 2 there are 2 ways to manage cache, going to “System -> Cache Management” in backend or using command line.
You can run commands in following ways:
cd <your Magento install dir>/bin
and run them as./magento <command name>
php <your Magento install dir>/bin/magento <command name>
1. View the cache status
magento cache:status
You can get a result like this:
1 2 3 4 5 6 7 8 9 10 11 |
config: 1 layout: 1 block_html: 1 collections: 1 db_ddl: 1 eav: 1 full_page: 1 translate: 1 config_integration: 1 config_integration_api: 1 config_webservice: 1 |
1 means “Enabled” and 0 means “Disabled”
2. Enable or Disable cache types
This command enables or disables all cache types or only the ones you specify
1 2 |
magento cache:enable [type] ... [type] magento cache:disable [type] ... [type] |
You can get each cache type code and its description here.
1 2 |
magento cache:enable magento cache:disable |
Above commands will enable/disable all cache types. You will get the cache types status after running the command.
3. Clean and Flush cache types.
What’s different between “Clean” and “Flush”
- Cleaning a cache type deletes all items from enabled Magento cache types only. In other words, this option does not affect other processes or applications because it cleans only the cache that Magento uses.Disabled cache types are not cleaned.
- Flushing a cache type purges the cache storage, which might affect other processes applications that are using the same storage.Flush cache types if you’ve already tried cleaning the cache and you’re still having issues that you cannot isolate.
Commands:
1 2 |
magento cache:clean [type] ... [type] magento cache:flush [type] ... [type] |
Please note:
magento cache:flush is equivalent “Flush Storage Cache” in System -> Cache Management
magento cache:clean is equivalent “Flush Magento Cache” in System-> Cache Management
That’s how we can manage cache Magento 2 using command line.