Magento 2.0 Cache System & Basic Concepts

June 16th, 2017| By

Magento 2 cache system will help your store to perform better and faster especially when you have more content. In this tutorial, we will learn about Magento 2.0 cache types and basic concept for example, How to enable or disable cache, how to clear cache, how to get current status of cache etc

Let’s checkout different types of cache in Magento 2.0.

Configuration 

Magento 2.0 collects various XML configuration settings and merges it and save it into the cache system. The storage location for this cache is either file system or database as admin user configure.

Every time we change the system configuration we need to clean/flush this cache to get the changes been reflected on your site.

The code name for this cache type is “config cache”.

LAYOUT

Magento 2.0 collect all the layout and stored the compiled version of the layout into the cache. We have to clean/flush this cache type after modifying layout files.

The Cache type code name of this cache is “layout“.

Block HTML output

This cache contains all the Html page fragments per block. We need to clean/flush this cache type after modifying the view layer.

The code name for this cache type is “block_html“.

Collections data

Magento stores the database schema into this cache type. Magento on its own cleans up this cache if necessary, but third party developer can put any data in any segment of the cache that magento can’t clean automatically so we need to manually clean that cache. We need to clean or flush this cache type after modifying or making changes to database schema.

The code name for this cache type is “collections“.

DDL

Magento stores the database schema into this cache type. magento automatically cleans up this cache if necessary, but third party developer can put any data in any segment of the cache that magento can’t clean automatically so we have to manually clean that cache. we have to clean or flush this cache type after modifying or making custom changes to the database schema.

There is one way to update the database schema automatically by using the following command:

php bin/magento setup:db-schema:upgrade

The code name of this cache type is “db_ddl“.

Entity attribute value (EAV)

This cache type contains all metadata related to the EAV attributes, for example, store labels, search settings, links to related PHP code, attribute rendering etc.

Basically, you don’t need to clean or flush this cache.

The code name of this cache type is “eav“.

Page cache

Page cache is the most important cache type and has an important role in improving the performance of our store. Full page cache stores the entire html pages output into the cache. Magento cleans up this cache automatically if it is necessary.

We have to clean or flush this cache type after modifying code level that affect HTML output. it’s recommended to keep this cache type enabled because it improves the performance of your website.

The Cache type code name of this cache is “full_page“.

Reflection

Any kind of api interface related reflections are stored in this cache. Typically you don’t need to clean or flush this cache type.

The Cache type code name of this cache is “reflection“.

Translations

Stores the Merged translations from all modules into cache. We need to clear this cache when we modified any translation file.

The Cache type code name of this cache is “translate“.

Integration configuration

Stores the Compiled integrations to cache. We need to clean or flush this cache type after changing or adding integrations.

The Cache type code name of this cache is “config_integration“.

Integration API configuration

Stores the Compiled integrations API to cache. We need to clean or flush this cache type after changing or adding integrations.

The Cache type code name of this cache is “config_integration_api“.

Web services configuration

This Cache type Store the web API Structure to the Cache systems.  Typically you don’t need to clean or flush this cache type.

The Cache type code name of this cache is “config_webservice“.

 

Below the Additional Cache types

  • Catalog Images Cache

Contains the Pregenerated product images files. Product resized images are saved in this cache . if you click On Flush Catalog Images Cache button it will remove all the images from the cache.

Path where the images are store is media/catalog/product/cache directory.

  • JavaScript/CSS Cache :

Combined and minified version of the javascript/css file is store into this cache. if you click on Flush JavaScript/CSS Cache button, it will remove the merged copies of JavaScript and CSS files

  • Static Files Cache :

All the static file contain store into this cache type. If you click on Flush Static Files Cache button, it will remove all the static file contain from the cache.

Path where the static file contain store is  pub/static/ Directory.

So, that’s all the cache type magento 2.0 include. That’s not mean we can’t add our own cache type, We can also added the custom type as well but that we see in future articles.

We can also store the cache programmatically by using following syntax :

  • To Store the Data into Cache:

The above syntax store the $data into the cache system. You can access this cache by its identifier.

  • To Get back the Data from Cache:

If the identifier found then all the data loaded into the $data variable.

  • How to Check the Cache Status :

By executing the following command, you will display the cache status

Php bin/magento cache:status

If everything goes ok you will see the following output:

  • How to Enable/Disable Cache Types :

Below Command enables you to disabled and enabled any cache type.

But make sure to disabled only necessary cache type because it has the huge effect on the website performance.

For example, You disabled the full page cache then your website going to be very slow.

Command options:

magento cache:enable [type] … [type]

magento cache:disable [type] … [type]

Where

[type] is the space separated list of cache type.

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

magento cache:disable db_ddl full_page

Sample output:

You can enable/disable all cache types simultaneously by omitting [type] option.

  • How to Clean and Flush Cache Types :

To remove/clean/purge out-of-date items from the cache we need to clear and flush the magento cache.

Clearing a cache from magento cleans all the items from the cache only. in other words, this process does not affect the other processes or application because it cleans only the cache that magento uses.

This process doesn’t clean the cache of disabled cache types.

Flushing the cache from magento means to clean all the cache storage. Clearing the cache only deletes the cache items but flushing delete all the data from the cache storage.

Command Options:

magento cache:clean [type] … [type]
magento cache:flush [type] … [type]

Where [type] is the space separated cache type list. Omit if you want to clean all the cache.

For example, to flush all cache types, enter

magento cache:flush

Sample Output :

Summary

We’ve tried to elaborate magento 2.0 cache system & its basic concepts. Apply given cache methods in your website to improve perfomance. If you’re looking for speeding up your Magento store, You’re at the right place.

At Elitech, We have an expert web development team of exceptionally talented, trained and well experienced front end developers and PHP Programmers who have strongly contributed in producing outstanding custom Magento eCommerce web applications.

We provide custom Magento development services  including theme customization, Speed optimisation, payment gateway integration and Magento2 latest version up-gradation. Our developer’s strong technical & domain expertise can contribute immensely to grow your business online.