Magento 2 – Correct Sequence to Flush All Caches and Static Files

cachecode generationmagento2

I'm having a hard time in development with generated classes, pre-processed files and caches in Magento2.

In comparisson with Magento1 it seems no longer possible to efficiently develop when disabling all caches, plus I also need to see if caches interfere with features I build.

My problem is, that there are so many caches and generated files, I'm not sure which are dependent of each other and in what sequence I should flush them in order to get a fresh view of all my developments.

There's the Backend Cache area

  • All the standard caches that can be cleaned
  • The Catalog image cache
  • The Static Files cache
  • The CSS/JS Cache

Then there is the bash commands

  • php bin/magento cache:clean
  • php bin/magento setup:static-content:deploy

Then there folders you can manually delete

  • var/generation
  • var/cache
  • var/page_cache
  • var/view_preprocessed
  • pub/static

That's a lot of possibilities and probably not all. So if I deploy a large update, Code Changes, CSS/JS changes, Template changes

Which of these steps should I do to get everything cleaned? In what sequence must these steps be done?

Best Answer

Normaly you don't have to clear the folder manually. I use the following "rotation"

For clearing the cache:

  • bin/magento cache:clean

For reindex new xml files:

  • bin/magento index:reindex
  • List item
  • bin/magento cache:clean

For refresh or insert new plugins:

  • bin/magento setup:upgrade
  • -d memory_limit=-1 bin/magento setup:static-content:deploy de_DE
  • bin/magento index:reindex
  • bin/magento cache:clean

If you need a "full-cleanup/refresh":

  • bin/magento setup:upgrade
  • -d memory_limit=-1 bin/magento setup:di:compile
  • -d memory_limit=-1 bin/magento setup:static-content:deploy de_DE
  • bin/magento index:reindex
  • bin/magento cache:clean
Related Topic