Magento Tutorials

How to Enable/Disable or Clear Cache in Magento 2

Hello SimiCart’s readers and Welcome you to this Magento tutorial.

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

In Magento 2 Backend

  1. In your Magento backend, go to System > Tools > Cache Management.
    cache refresh
  2. Check the box on which cache type you want to enable/disable. Then on the top left corner, select the appropriate action (Enable/Disable) and click the Submit button.

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.

Command options:

magento cache:enable [type] ... [type]
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:

magento cache:status

For example, to disable the full page cache and the DDL cache:

magento cache:disable db_ddl full_page

Sample result:

Changed cache status:
 db_ddl: 1 -> 0
 full_page: 1 -> 0

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.

In Magento 2 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,
    • Click Flush Magento Cache if you want to clean cache. This is equivalent to magento cache:clean
    • Click Flush Cache Storage if you want to flush cache. This is equivalent to magento cache:flush
  3. 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:
    • 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.
    • 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.
    • Flush Static Files Cache: Removes preprocessed view files and static files.
    • Make sure to also clear the cache of your browser.

Using Command Line

Command usage:

magento cache:clean [type] ... [type]
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:

magento cache:flush

Sample result:

Flushed cache types:
config
layout
block_html
collections
db_ddl
eav
full_page
translate
config_integration
config_integration_api
config_webservice

View the Cache Status

To view the status of the cache, enter

magento cache:status

Sample result:

                config: 1
                layout: 1
            block_html: 1
           collections: 1
                db_ddl: 1
                   eav: 1
             full_page: 1
             translate: 1
    config_integration: 1
config_integration_api: 1
     config_webservice: 1

Overview of Cache Types

Magento 2 has the following cache types:

Cache typeCode nameDescription
ConfigurationconfigMagento collects configuration from all modules, merges it, and saves the merged result to the cache. This cache also contains store-specific settings stored in the file system and database.

 

Clean or flush this cache type after modifying configuration files or settings within the admin panel.

LayoutlayoutCompiled page layouts (that is, the layout components from all components).

 

Clean or flush this cache type after modifying layout files.

Block HTML outputblock_htmlHTML page fragments per block.

 

Clean or flush this cache type after modifying the view layer.

Collections datacollectionsResults of database queries.

 

If necessary, Magento cleans up this cache automatically, but third-party developers can put any data in any segment of the cache.

Clean or flush this cache type if your custom module uses logic that results in cache entries that Magento cannot clean.

DDLdb_ddlDatabase schema.

 

If necessary, Magento cleans up this cache automatically, but third-party developers can put any data in any segment of the cache.

Clean or flush this cache type after you make custom changes to the database schema. (In other words, updates that Magento does not make itself.)

One way to update the database schema automatically is using the magento setup:db-schema:upgrade command.

Entity attribute value (EAV)eavMetadata related to EAV attributes (for example, store labels, links to related PHP code, attribute rendering, search settings, and so on).

 

You should not typically need to clean or flush this cache type.

Page cachefull_pageGenerated HTML pages.

 

If necessary, Magento cleans up this cache automatically, but third-party developers can put any data in any segment of the cache.

Clean or flush this cache type after modifying code level that affects HTML output. It’s recommended to keep this cache enabled because caching HTML improves performance significantly.

ReflectionreflectionRemoves a dependency between the Webapi module and the Customer module.
TranslationstranslateMerged translations from all modules.
Integration configurationconfig_integrationCompiled integrations.

 

Clean or flush this cache after changing or adding integrations.

Integration API configurationconfig_integration_apiCompiled integration APIs.
Web services configurationconfig_webserviceWeb API structure.

Related posts:

How to Configure Full-Page Cache in Magento 2

How to Enable or Disable Modules in Magento 2

Dom

A knowledge craver who always strive to be wiser everyday.

Subscribe
Notify of
guest

4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Dick McLeester
Dick McLeester
5 years ago

This tutorial was not enough for me. I am just an end user of my Magento 2 site, not a programer. My host said that I needed to Flush Cache for my website, so it did not take up too much space on their site. I went to System / Cache Management and got the screen you show. Not clear what else to do. So on the top I hit Clear Cache. I said it cleared the cache and this was better. Then I noticed 3 buttons at the bottom of that screen for clearing the cache on other parts.… Read more »

trackback

[…] Resim kaynağı: SimiCart […]

trackback

[…] Afbeeldingsbron: SimiKart […]