Contents
- Overview of cache types
- First steps
- View the cache status
- Enable or disable the cache
- Clean and flush cache types
Overview of cache types
Magento 2 has the following cache types:
Cache type "friendly" name | Cache type code name | Description |
---|---|---|
Configuration |
config |
Magento 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. |
Layout |
layout |
Compiled page layouts (that is, the layout components from all components). Clean or flush this cache type after modifying layout files. |
Block HTML output |
block_html |
HTML page fragments per block. Clean or flush this cache type after modifying the view layer. |
Collections data |
collections |
Results 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. |
DDL |
db_ddl |
Database 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) |
eav |
Metadata 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 cache |
full_page |
Generated 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鈥檚 recommended to keep this cache enabled to because caching HTML improves performance significantly. |
Reflection |
reflection |
Removes a dependency between the Webapi module and the Customer module. |
Translations |
translate |
Merged translations from all modules. |
Integration configuration |
config_integration |
Compiled integrations. Clean or flush this cache after changing or adding integrations. |
Integration API configuration |
config_integration_api |
Compiled integration APIs. |
Web services configuration |
config_webservice |
Web API structure. |
First steps
-
Log in to the Magento server as, or switch to, a user who has permissions to write to the Magento file system. One way to do this is to switch to the Magento file system owner.
If you use the bash shell, you can also use the following syntax to switch to the Magento file system owner and enter the command at the same time:
su <Magento file system owner> -s /bin/bash -c <command>
-
To run Magento commands from any directory, add
<your Magento install dir>/bin
to your systemPATH
.Because shells have differing syntax, consult a reference like unix.stackexchange.com.
bash shell example for CentOS:
export PATH=$PATH:/var/www/html/magento2/bin
You can also run the commands in the following ways:
cd <your Magento install dir>/bin
and run them as./magento <command name>
php <your Magento install dir>/bin/magento <command name>
<your Magento install dir>
is a subdirectory of your web server's docroot. Need help locating the docroot? Click here.
In addition to the command arguments discussed here, see Common arguments.
View the cache status
To view the status of the cache, enter
magento cache:status
A sample follows:
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
Enable or disable cache types
This command enables you to enable or disable all cache types or only the ones you specify. 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 an adverse affect 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.
type
is a space-separated list of cache types.
To list cache types and their status, enter
magento cache:status
For example, to disable the full page cache and the DDL cache, enter
magento cache:disable db_ddl full_page
Sample result:
Changed cache status:
db_ddl: 1 -> 0
full_page: 1 -> 0
Enabling a cache type automatically clears that cache type.
Clean and flush cache types
To purge 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 are not cleaned.
-
Flushing a cache type purges the cache storage, which might affect other processes applications that are using the same storage.
Flush cache types if you鈥檝e already tried cleaning the cache and you鈥檙e still having issues that you cannot isolate.
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, enter
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
You can also clean and flush cache types in the Magento Admin. Go to System > Tools > Cache Management. Flush Cache Storage is equivalent to magento cache:flush
. Flush Magento Cache is equivalent to magento cache:clean
.
Find us on