Magento 2 clear cache command line

(2020 Guide) Magento 2 Clear Cache /Flush Cache Command Line

by admin

Every merchant should know ways of Magento 2 Clear Cache/Magento 2 Flush Cache. It is simple, but might not perform properly all the time!


But before start with the ultimate guide on how to clear or flush cache in Magento 2, get an overview first.


The functionality of the cache could be visualized to that part of a memory brain, which is relatively not ample. A cache is of engine factors accelerating the loading speed of a Magento 2 site, but it could reverse its-so-called-duty by clogging the flow if the database exceedingly accumulates in one small place. In Magento 2 cache system, there are more than 12 typical kinds of cache to store various data – see cache overview here.

When You Need Perform Magento 2 Clear Cache or Magento 2 Flush Cache?

Any Magento 2 users must have been familiar with a repeatedly yellow hung up notification bar said “one or more of the Cache Types are invalidated” found after any adjustment was made for your site. As long as you are with Magento 2, it seems to continually ask to refresh cache types in order to liberate the cache to execute your commands.


Magento Flush Cache notification

The reason the system endlessly asks you to Magento 2 clear cache is that if it was not cleared on a regular frequency, the likely chance of causing a jam or miscarry your commands would happen.


This article’s purposes are to guide you on how to use the command line to clear cache without the support of developers; furthermore, to compile all possible ways to help you address that matter in Magento 2 CE – a task you should always perform as long as you are with Magento 2.

CLICK NOW if you also want to KNOW >>>  How to Do Magento 2 Full Page Cache?

How to Complete Magento 2 Clear Cache Using Command-Line?

Commonly, the cache can either be cleaned manually from using Command-Line; the other way is to clear manually in Admin Panel. There are two more ways to clean them programmatically or to create extension automatically refreshing cache using cron in Magento 2, which may require more technical knowledge and consultant from developers.

1. Manually do Magento 2 flush cache using Command line

In term of Magento 2 enable cache and Magento 2 disable cache, enter:

bin/magento cache:enable [type] ... [type]
bin/magento cache:disable [type] ... [type]

Omit type to Magento 2 enable cache/ Magento 2 disable caches. The type option is a space-separated list of cache types.

php bin/magento cache:clean [type] ... [type]
php bin/magento cache:flush [type] ... [type]

The type option is a space-separated list of cache types.


-To flush all cache types, enter:

php bin/magento cache:flush

For example, to make Magento 2 disable cache and the Entity attribute value (EAV):

php bin/magento cache:disable eav full_page

-To check cache status, enter:

php bin/magento cache:status

– To clean the static file cache, applying those steps:


Clear  pub/static and var/view_preprocessed directories and subdirectories except for pub/static/.htaccess.


-To clear the pub/static directory of all files except .htaccess (which is a hidden file), enter the following command:

rm -R pub/static/*

2. Manually do Magento 2 flush cache from Admin Panel

2.1. How to do Magento 2 flush cache?

Login to Admin Panel, find System and choose cache management


Admin Panel > Cache Management

You will see the cache grid management table. It is essential to define which cache is going to be pursed. If you perform Magento 2 disable cache for the targeted cache, you need to do Magento 2 enable cache on the ground that disabled cache types are not cleaned.


Magento 2 disable cache

How to manipulate:

  • Select Cache Type, in the drop-down menu, choose to Enable then Submit.
  • After Enable, once again in the drop-down menu choose Refresh then Submit.

This action does not interrupt other processes or applications because it cleans only the cache that Magento uses only.


Action: Refresh Cache

2.2.  How to do Magento 2 flush cache in Admin Panel?

In case you follow the above guides precisely, but your site remains incapable of processing or resolving issues, you should flush the cache to delete all Magento flush cache storage. This action might affect some processes applications sharing one storage (for example other websites).


You will see this row below Cache Management


Magento Flush Cache buttons

Hit Magento Flush Cache to purge all default Magento cache with associated Magento tag.


Hit Flush Cache Storage to purge all items of Magento flush cache storage regardless of its tag.


There is also additional Cache Management under the cache grid table to clean.


Additional cache management

Hit Flush Catalog Images Cache to clear away the catalog images from all sections; for example:



Hit Flush JavaScript//CSS Cache to discard a merged copy of JavaScript – CSS files from the cache.


Hit Flush Statics Files Cache to remove preprocessed view files and static files.


Refresh your site after each step to check accomplishment.

3. Programmatically Magento 2 clear cache  

3.1 Define constructor
public function __construct(
    Context $context,
    \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
    \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
) {
    $this->_cacheTypeList = $cacheTypeList;
    $this->_cacheFrontendPool = $cacheFrontendPool;
 3.2   Define cache you want to delete/ flush
   $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
foreach ($types as $type) {
foreach ($this->_cacheFrontendPool as $cacheFrontend) {


Get the extension for Automatically Refresh Cache using Cron

See extension for the auto Magento flush cache using Cron in this link.

CHECK NOW Magento 2 Extensions at BSS Commerce to power your business.

About us:

BSS Commerce is one of the leading Magento extension providers and web development services in the world. With experienced and certified Magento developers, we commit to bring high-quality products and services to optimize our business effectively.


CONTACT NOW to let us know your problems. We are willing to support you every time you need to audit and maintain your Magento website

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.