Kindly Clear Difference Between php bin/magento cache:flush and cache:clean and when they need to Run . which tasks Output to need cache:flush or clean ** and which task need these Commands => **di:compile,setup:upgrade,setup:static-content:deploy

I consume 4 to 5 min to run cache:flush,upgrade and deploy.


3 Answers 3


Although question have already been answered and accepted as well, but i thought it would be nice to compile all points in single answer for better understanding and for other users who are searching for such understanding:

So we will go part by part of question(s):

Question Part A :

Kindly Clear Difference Between php bin/magento cache:flush and cache:clean

as @Shoib Answers, cache:flush destroys the cache storage and build cache again where as cache:clean cleans the cache and doesn't destroy the storage.

Question Part B :

which tasks Output to need cache:flush or clean

when to Cache Clean ?

When you make any change in template, layout or configurations , only clean cache, you should avoid cache:flush in any case. 90% your frontend , configuration issues will be solved by cache:clean.

HINT : During frontend theme development, you can enable all caches just disable full_page cache, this will save you lot of time and in development, you just need to run cache:clean command.

When to Cache Flush ?

Cache flush only and only , if your desired changes not worked as expected after cache:clean command.

Question Part C :

which task need these Commands => **di:compile,setup:upgrade,setup:static-content:deploy

In part c of your question, you mentioned commands like :

1 - **di:compile** , 2 - **setup:upgrade** , 3 - **setup:static-content:deploy**

Let's re-order these as per usage and recommendation of commands :

  • 1 - setup:upgrade

  • 2 - di:compile

  • 3 - setup:static-content:deploy

1 - setup:upgrade :

When you add new module you should run this command this command will add your module entry in setup_module table and also in config.php file. As it updates the Database schema.

2 - setup:di:compile

This command is used to create factories, proxies, interceptors etc :

  • Application code generation (factories, proxies, and so on)
  • Area configuration aggregation (that is, optimized dependency injection configurations per area)
  • Interceptor generation (that is, optimized code generation of interceptors)
  • Interception cache generation
  • Repositories code generation (that is, generated code for APIs)
  • Service data attributes generation (that is, generated extension classes for data objects)

in short run this command when you make any change in your module classes files, constructor etc and generates the contents of the var/di folder in Magento <2.2 and generated for Magento >= 2.2. Refer to Magento Dev Docs for complete detail

3 - setup:static-content:deploy

Run this command when you are developing / making changes in your theme LESS or other JS / static files. Static view files are located in the /pub/static directory, and some are cached in the /var/view_preprocessed directory as well.

For more details about static content refer to Magento Dev Docs here and you can also read in which mode you should run which command.

Note :

If you make any change in template or layout file, php bin/magento cache:clean command will work for you , you don't need to deploy static content.

Hope this will help to understand mechanism.


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.

Flushing a cache type purges the cache storage, which might affect other processes applications that are using the same storage.

In short: Clean is a soft way of cleaning cache whereas flush is the hard flush of cache storage.

Reference: https://devdocs.magento.com/guides/v2.3/config-guide/cli/config-cli-subcommands-cache.html

Magento 2: What is difference between Cache Clean & Cache Flush?

  • what mean of which might affect other processes applications that are using the same storage ? which other process ?
    – HaFiz Umer
    Feb 27, 2019 at 6:52
  • 1
    Like third-party developers can put any data in any segment of the cache. They can use your cache storage. So, when you clean, it will not effect anything, whereas if you flush cache it will also flush third party module's cache. Then that module will regenerate cache in cache storage Feb 27, 2019 at 7:01
  • yes clean ! third-pary modules .
    – HaFiz Umer
    Feb 27, 2019 at 7:03
  • when setup:di:compile run then why need to run also cache:flush and also upgrade,deploy
    – HaFiz Umer
    Feb 27, 2019 at 7:11
  • @HaFizUmer see answer that Muhammad Ahmed has given, he described when to run other commands Feb 27, 2019 at 16:53
bin/magento setup:di:compile

This command is used when you make change in di file or create new plugin or preference.

bin/magento setup:upgrade

This command is used when you make a new module and you want to used it in your magento project.

bin/magento indexer:indexer

When you make a change on frontend then you need to use this command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.