Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

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:status

The command prints the list of cache types and the status of each: 1 — enabled, 0 — disabled.

TypeWhat it storesWhen to clean
configMerged XML files from etc foldersAfter editing any XML in etc
layoutMerged layoutsAfter editing a layout
block_htmlRendered block HTMLAfter editing a template
full_pageWhole pagesAfter any change visible on the storefront
translateTranslationsAfter editing translation files
eavAttribute definitionsAfter changing attributes

Cleaning the cache

bin/magento cache:clean
bin/magento cache:clean config layout
bin/magento cache:flush

The 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.

CommandWhat it removes
cache:cleanOnly Magento entries of enabled cache types
cache:flushEverything 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:enable

The 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_price

The first command shows the status of every indexer, the second recalculates all of them, the third only prices.

IndexerWhat it prepares
catalog_product_priceFinal prices
cataloginventory_stockProduct availability
catalog_category_productProducts in categories
catalogsearch_fulltextData for search in OpenSearch

Indexer modes

bin/magento indexer:set-mode schedule
bin/magento indexer:show-mode
ModeHow 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.

Thanks for reading!

Donate to the site — we work hard for you.