How to Enable Disable Magento 2 caches

From Brian Nelson Ramblings
Jump to: navigation, search

How to Enable Disable Magento 2 caches

Magento cache are pages (or parts of pages) that are stored to improve the page load time of subsequent requests.

A cache stores data so that future calls for that data can be loaded quicker, and Magento includes these types:

  • configuration
  • layout
  • block HTML layout
  • full page (the most well-known)
  • collections
  • DDL
  • EAV
  • reflection
  • translation
  • integration configuration
  • integration API configuration
  • web services configuration.

Other types can be created and defined.

Enable/disable cache types via Backend

In Magento 2 backend In your Magento backend, go to System > Tools > Cache Management. Enable them all to prevent slow sites

Enable/disable cache types via CLI

Using command line This command allows you to enable or disable some or all cache types.

Disabling cache types is useful during development because you see the results of your changes without having to flush the cache; however, disabling cache types has some negative effect on performance.

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

Where omitting [type] enables or disables all cache types at the same time. The type option is a space-separated list of cache types.

To list cache types and their status:

php bin/magento cache:status

Clear cache in Magento 2

To clear 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 will not be cleaned.
  • Flushing a cache type clears the cache storage, which might affect other processes or applications that are using the same storage.

You should only flush cache types if you’ve already tried cleaning the cache and you’re still having issues that you cannot isolate.

Clear Magento 2 via Backend

  1. In your Magento backend, go to System > Tools > Cache Management.
  2. Check the box on which cache type you want to clean/flush. Then,
  3. Click Flush Magento Cache if you want to clean cache. This is equivalent to magento cache:clean
  4. Click Flush Cache Storage if you want to flush cache. This is equivalent to magento cache:flush

For further cache clean/flush, you can also scroll down to Additional Cache Management section, where you’re able to flush these types of cache:

  1. Flush Catalog Images Cache: Removes all automatically resized and watermarked catalog images that are stored at: media/catalog/product/cache. If recently uploaded images aren’t reflected in the catalog, try flushing the catalog and refreshing your browser.
  2. Flush JavaScript/CSS Cache: Removes the merged copy of JavaScript and CSS files from the cache. If recent changes to the style sheet or JavaScript aren’t reflected in the store, try flushing the JavaScript/CSS cache and refreshing your browser.
  3. Flush Static Files Cache: Removes preprocessed view files and static files.

Make sure to also clear the cache of your browser.

Clear Magento 2 via CLI

Command usage:

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

Where [type] is a space-separated list of cache types. Omitting [type] cleans or flushes all cache types at the same time. For example, to flush all cache types:

php bin/magento cache:flush

You can view the caches to see if they are enabled by running:

php bin/magento cache:status