There are several cache types in Magento 2. The caching system of Magento 2 supports your online store’s performance especially you enrich it with content. So why we need to clear cache? you will not see any change you have made to your Magento website until you clear the cache.
In this tutorial, we will learn how to clear cache in Magento 2 via admin and how to clear cache in Magento 2 programmatically using command line (CLI).
You may interest: Top 5 Magento hosting for high performance website
Magento 2 cache overview
In this section, we will have an overview about different basic types of cache in Magento 2.
- Cache type code name: config
- Description: this Cache possesses configuration and store specific settings. Magento 2 collects configuration from all modules, merges them and then save to the Cache. It needs flushing after modifying configuration files.
- Cache type code name: layout
- Description: this Cache contains the compiled page layout from all components. It needs flushing after modifying layout files.
3.Block HTML output:
- Cache type code name: block_html
- Description: this Cache possesses HTML page fragments per block. It needs flushing after modifying view layer of the store.
- Cache type code name: collections
- Description: this Cache collects results from database queries. It is usually cleaned automatically by Magento 2. In case custom modules write entries which is uncrushable by Magento automatically, it needs flushing manually.
- Cache type code name: reflection
- Description: this Cache removes a dependency between the Webapi module and the Customer module. Any API interfaces reflection data is cached by this.
6.Database DDL operations:
- Cache type code name: db_ddl
- Description: this Cache holds custom changes to the database schema. Although Magento can clean up this cache automatically, third-party developers are able to put any data in any segment of the cache. It needs flushing after modifying database schema which are the updates that Magento does not make itself. the Magento set up “db_schema: upgrade” command allows the database schema update automatically.
7. EAV types and attributes (Entity Attribute Value- EAV ):
- Cache type code name: EAV
- Description: this Cache collects metadata related to EAV attributes including store labels, links to related PHP code, attribute rendering, search setting, etc. It is worth to notice that you should not clean or flush this cache type.
8. Intergration Configuration:
- Cache type code name: config_intergration
- Description: this Cache compiles integrations of your online store(s). It needs flushing after changing or involving integrations.
9. Intergration API Configuration:
- Cache type code name: config_intergration_api
- Description: this Cache compiles integrations of APIs. It needs flushing after modifying configuration files.
- Cache type code name: full_page
- Description: this Cache generates HTML pages. It is usually cleaned up automatically by Magento 2. Third party developers, however, still can put any data in any segment of the cache. It needs flushing after modifying code level affecting HTML output. It is recommended to remain this cache enabled since caching HTML significantly improve the page performance.
- Cache type code name: translate
- Description: this Cache merges translation from all modules.
12.Web service Configuration:
- Cache type code name: config_webservice
- Description: this Cache contains the Web API structure of the website. It needs flushing after modifying configuration files.
How to clear the Cache?
Clear cache using command line
In Magento 2, we can clear cache using this command line:
php bin/magento cache:clean
To Flush cache, use this command
php bin/magento cache:flush
The different between Flush and Clean commands is:
- Clean: deletes all items from enabled Magento cache types only.
- Flush: purges the cache storage and it might affect other processes that are using the same storage.
Clear cache using admin backend
First, you need to understand appropriately all the cache types (please refer to the section above) and specify the types of cache you want to refresh.
Login to the back-end of your store page. On the Admin panel, go to System > Cache Management.
You will see several caches in the list:
Read the Description column very carefully to decide whether or not you need to flush the cache. Then, select the caches that you want to enable. Select Enable and click Submit.
Following that, select the Caches that you have enabled and click Submit again.
The selected types of caches are refreshed. Use the Flush Magento Cache or Flush Cache Storage on the top right corner to clear Magento cache or storage, respectively. The Flush Magento Cache cleans all the default Magento Cache items that have Magento tag while the later removes all items with and without Magento tag.
One specific note is about Full Page Cache which can distort the speed of response and reduce the server load. The Caching Applications are supported by Magento 2 in Varnish Caching and Built-in Application. It is recommended to define Lifetime for public content. It’s default by 86,400 seconds. The store’s speed can also be improved by building in Full Page Cache extension.