Magento 2 Cache Management

- Magento 2
 

How to Manage Magento 2 Cache

Below, I shed light on cache management in Magento 2. Since the second version of the platform differs from the current one, it is vitally important to understand all the nuances related to Magento 2 Cache Management. Let’s start with cache types available in Magento 2.

Everything about Magento 2 on Firebear

Cache Types of Magento 2

The second version of the platform works with the following types of cache:

  • Configuration (config) cache – this cache appears when Magento gathers configuration from all its modules, merges it, and saves to the cache. Additionally, it includes store-specific settings from the file system and database. You should flush or clean this type of cache after changing configuration files.

  • Layout (layout) cache consists of compiled page layouts . As you might have guessed, this cache type requires cleaning or flushing after you modify layout files.

  • Block HTML output (block_html) cache – this one is about HTML page fragments per each block. Clean or flush block_html cache after changing the view layer.

  • Collections data (collections) cache is related to database queries. Magento offers an automated cleaning for this cache if necessary. At the same time, it is possible to put any data in any segment of collections cache . Please note you should flush it if your custom modules use logic that leads to cache entries that Magento is unable to clean.

  • DDL (db_ddl) cache – it is all about database schema. It can be cleaned up automatically as well, and it is possible to put any data in any segment of db_ddl cache . The cache should be flushed after custom changes to the database schema.

  • Entity attribute value (eav) cache – this cache includes Metadata related to EAV attributes, such as store labels, search settings, attribute rendering, etc. There is no need to flush or clean  this cache.

  • Page cache (full_page) cache occurs due to generated HTML pages. It is automatically cleaned by Magento and can be modified by but third-party developers.  Clean full_page cache after changing code level that influences HTML output.

  • Translations (translate) cache consist of merged translations from all modules.

  • Integration configuration (config_integration) cache is related to compiled integrations. Clean it after adding new integrations or modifying existing ones.

  • Integration API configuration (config_integration_api) cache is about compiled integration APIs.

  • Web services configuration (config_webservice) cache – the cache of web API structure.

Prerequisites

  1. You should be logged in to the Magento server as a user with permissions to write to the Magento file system. Just switch to the web server user.

  2. For running Magento commands from any directory, take the following code and add it to the system PATH.

Since shells often have differing syntax, you should check this page or a similar source for more help. The CentOS example has the following look:

These are some other ways for runing the commands:

1.

run them as:

2.

<your Magento install dir> is a subdirectory of your web server’s docroot. If you have any troubles while locating the docroot, check this page for help.

More arguments: Common arguments.

How to Check the Cache Status

By entering the following code, you will display the cache status

If everything is of, it should look like this one:

How to Enable/Disable Cache Types

With the aid of the below command options, you can simultaneously enable or disable all cache types or work only with specified ones. Disabling cache types is necessary while development, since it provides the ability to see the results of your improvements without flushing cache. You should also remember that this procedure significantly decrease performance. So use the following command options to enable/disable cache.

where [type] is a space-separated list of cache types. You can enable/disable all cache types simultaneously by omitting this option.

View the list of cache types and status, with

In case when you need to disable the DDL cache and the full page cache, use the following command

This is how the result should look like:

How to Clean and Flush Cache Types

To delete outdated items from cache, you should clean or flush it. Consider the following:

  • If you clean a cache type, you delete all items only from the enabled types. Disabled types remain unaffected.

  • If you flushing a cache type you purge its storage. Please note that all cache types with a specified storage are flushed.

Use the below commands to clean or flush cache respectively:

where [type] is a list of your cache types separated with a space.  Omit it to clean or flush all cache types simultaneously.

To clean all cache types, enter

You should get the following result:

Congratulations! Now, you know how to work with cache in Magento 2. In case of problems, live your comments below – the Firebear team will always help you.

To check the official documentation, related to cache management of Magento 2, visit this page: Manage the cache. Check the demo of Magento version 2 here: Magento 2 Demo.