Magento cache overview

Caching is one of the most effective way of improving performance of web applications of all kinds. Generally speaking, there are two ways to cache: client-side (browser) and server-side. In addition, there are two types of content: public (available to multiple customers) and private (specific to one customer).

Magento page caching is synonymous with full-page caching; in other words, we cache the entire page. The Magento application gives you the following options:

  • The default caching mechanism which stores cache files in any of the following:

    • On the file system.

      You don’t need to do anything to use file-based caching.

    • Database
    • Redis
  • Varnish (recommended)

Cacheable and uncacheable pages

Cacheable and uncacheable are terms we use to indicate whether or not a page should be cached at all. (By default, all pages are cacheable.) If any block in a layout is designated as uncacheable, the entire page is uncacheable.

To create an uncacheable page, mark any block on that page as uncacheable in the layout using cacheable="false".

Examples of uncacheable pages include the compare products, cart, checkout pages, and so on.

Example

Do not configure content pages (that is, catalog, product and CMS pages) to be uncacheable. Doing so has an adverse affect on performance.

Cache types

The following cache types mostly have impact on frontend development process:

Cache type “friendly” name Cache type code name Description
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.
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’s recommended to keep this cache enabled because caching HTML improves performance significantly.
Translations translate Merged translations from all modules.

The full list of cache types can be found in the Overview of cache types topic.

Clean cache

To clean cache, run

magento cache:clean <type> ... <type>

To view the status of the cache, run:

`php bin/magento cache:status`

For more details about working with cache, see Manage the cache

Clean static files

Besides the cached files, inn theme development process developers also deal with other saved files - static view files that are preprocessed and published to the var/view_preprocessed and pub/static directories correspondingly. In most cases when working on a custom theme, for example, if you are only working on styles, you do not need to clean cache, but need to clean the previously preprocessed and published static view files. To clean them, run grunt clean <theme> or manually clear the pub/static and var/view_preprocessed directories.