Cache and indexers
On every request Magento assembles hundreds of XML files, blocks and prices. To avoid doing this again, the finished result is remembered: this is the cache. Indexers play a similar role — tables recalculated in advance for the catalog. Both mechanisms explain why an edit is sometimes "not visible", and both are managed from the console.
Cache types
bin/magento cache:statusThe command prints the list of cache types and the status of each: 1 — enabled, 0 — disabled.
| Type | What it stores | When to clean |
|---|---|---|
config | Merged XML files from etc folders | After editing any XML in etc |
layout | Merged layouts | After editing a layout |
block_html | Rendered block HTML | After editing a template |
full_page | Whole pages | After any change visible on the storefront |
translate | Translations | After editing translation files |
eav | Attribute definitions | After changing attributes |
Cleaning the cache
bin/magento cache:clean
bin/magento cache:clean config layout
bin/magento cache:flushThe first command cleans all cache types, the second only the named ones. The third empties the whole storage, including other programs' entries if the storage is shared.
| Command | What it removes |
|---|---|
cache:clean | Only Magento entries of enabled cache types |
cache:flush | Everything in the cache storage |
During development cache:clean is usually enough.
Enabling and disabling
bin/magento cache:disable full_page block_html
bin/magento cache:enableThe first command disables two cache types — this makes editing templates easier. The second, without arguments, enables all types. On a production server the whole cache is enabled.
The full page cache
The full_page type stores the finished HTML of a page and serves it while running almost none of the module code. So an action and a view model run only on the first request to a page. On production servers a separate program, Varnish, usually takes this role, and the cache itself and sessions are stored in Redis or Valkey.
Data that differs for each customer — the name, the cart — is loaded by a separate JavaScript request after the page has been served.
Indexers
A product price with discounts, stock availability, category membership are expensive to compute on every view. Magento recalculates them in advance into separate tables — indexes.
bin/magento indexer:status
bin/magento indexer:reindex
bin/magento indexer:reindex catalog_product_priceThe first command shows the status of every indexer, the second recalculates all of them, the third only prices.
| Indexer | What it prepares |
|---|---|
catalog_product_price | Final prices |
cataloginventory_stock | Product availability |
catalog_category_product | Products in categories |
catalogsearch_fulltext | Data for search in OpenSearch |
Indexer modes
bin/magento indexer:set-mode schedule
bin/magento indexer:show-mode| Mode | How it updates |
|---|---|
realtime (Update on Save) | Right when a product is saved; saving is slower |
schedule (Update by Schedule) | By the scheduler once a minute; requires working cron |
On a production server choose schedule.
Common mistake
A block with the cacheable="false" attribute is added to a layout so that it always shows fresh data. One such block disables the full page cache for the whole page it is on, and in the default.xml file — for the whole shop, and the site becomes slow. Load customer-specific data through JavaScript and keep blocks cacheable.