18

In Magento 2 we have 2 commands

php bin/magento cache:flush
php bin/magento cache:clean

What's the exact difference between them? I'm generally using cache:flush. I never used cache:clean. So, when to use which command & in which situation?

27

To purge out-of-date items from the cache, you can clean or flush cache types:

  • 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.

Source: https://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cache.html#config-cli-subcommands-cache-clean

11

php bin/magento cache:clean

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.

php bin/magento cache:flush

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

Reference: DevDocs Manage the cache

  • Thanks @Rafael. So which is best & when to use? – Ankit Shah Sep 27 '16 at 1:49
  • Depends, but I prefer cache:clear – Rafael Corrêa Gomes Sep 27 '16 at 1:59
  • I've tried to create an empty file on var/cache and it was not deleted by any of these commands as you mentioned. But thanks for that anyway. – Ricardo Martins Sep 27 '18 at 9:08
  • @RicardoMartins it is because you need to create a file like var/cache/mage--test-martines – Rafael Corrêa Gomes Sep 28 '18 at 12:59
  • This answer is the opposite of the chosen answer If I am correct – Patrick van Efferen Jan 14 at 13:03
1

Quoting Fabrizio Branca for this one:

(...) Magento that comes with those two different actions in the first place (you'll also find two buttons on the cache management page).

While cache:clean deletes the cache storage by tags cache:flush will wipe out everything.

There are two major differences here:

  • some things are stored into the cache without the proper tags. cache:clean will not delete those.
  • other things might be using the same cache storage (this is not recommended, but sadly sometimes this is the case). Flushing the cache will result in everything being deleted. So if multiple Magento instances use the same cache storage or if you store your sessions in the same Redis database you're using for the cache (please don't! :) then they will also be gone.
0

Using bin/magento cache:clean you can specify(comma-separated) cache types you want to clean.

Supported types:

config, layout, block_html, collections, reflection, db_ddl, eav,
customer_notification, target_rule, full_page, config_integration,
config_integration_api, translate, config_webservice
0

While cache:clean deletes the cache storage by tags cache:flush will wipe out everything.

There are two major differences here:

some things are stored into the cache without the proper tags. cache:clean will not delete those. other things might be using the same cache storage (this is not recommended, but sadly sometimes this is the case). Flushing the cache will result in everything being deleted. So if multiple Magento instances use the same cache storage or if you store your sessions in the same redis database you're using for the cache (please don't! :) then they will also be gone.

Source : https://github.com/netz98/n98-magerun/issues/588#issuecomment-112453280

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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