35

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?

asked Sep 27, 2016 at 1:26
1

6 Answers 6

41

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

answered Sep 27, 2016 at 4:47
3
  • 2
    Can I know which are the other processes applications which will use Magento cache storage. Commented Sep 4, 2019 at 14:39
  • You can enable performance in Magento by configuring Configuring Redis for backend cache,Configuring Memcached for session caching and Configuring Varnish as a Full Page Cache (This is explained in detail in Magento 2 Cook Book by Ray Bogman). The other applications in sense if you have a single Redis or any other server running and configured with more than one Magento or any other applications. Running Flush will delete all directory + files but running clean will delete files alone in \Magento\var\cache dir. Commented Oct 23, 2019 at 9:11
  • 1
    @BalaVaradarajan I'm afraid I don't get it. Does anyone do that? I wouldn't come up with the idea to share a cache with different applications or Magento instances. Sounds very special. Commented Jan 22, 2020 at 7:27
14

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

answered Sep 27, 2016 at 1:46
6
  • Thanks @Rafael. So which is best & when to use? Commented Sep 27, 2016 at 1:49
  • Depends, but I prefer cache:clear Commented Sep 27, 2016 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. Commented Sep 27, 2018 at 9:08
  • @RicardoMartins it is because you need to create a file like var/cache/mage--test-martines Commented Sep 28, 2018 at 12:59
  • This answer is the opposite of the chosen answer If I am correct Commented Jan 14, 2019 at 13:03
5

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.

Other resources:

answered Sep 27, 2018 at 9:13
1

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.

answered Nov 5, 2019 at 14:39
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
answered Jan 17, 2017 at 13:42
1
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

answered Dec 25, 2018 at 14:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.