Page caching

Caching is one of the most effective ways to improve website performance. Generally speaking, there are two methods of caching content:

Retrieving stored (cached) content from a previous request for the same client instead of requesting files from your server every time someone visits your site is a more efficient use of network bandwidth.

The Adobe Commerce and Magento Open Source page cache library contains a simple PHP reverse proxy that enables full page caching out of the box. A reverse proxy acts as an intermediary between visitors and your application and can reduce the load on your server.

We recommend using Varnish, but you can use the default caching mechanism instead, which stores cache files in any of the following:

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 except the checkout pages.) 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".

<block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Magento_Customer::form/edit.phtml" cacheable="false">
    <container name="form.additional.info" as="form_additional_info"/>
</block>

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

Example

data-variant=warning
data-slots=text
Do not configure content pages (i.e., catalog, product, and CMS pages) to be uncacheable. Doing so has an adverse affect on performance.

Public and private content

Reverse proxies serve "public" or shared content to more than one user. However, most Adobe Commerce and Magento Open Source websites generate dynamic and personalized "private" content that should only be served to one user, which presents unique caching challenges. To address these challenges, the application can distinguish between two types of content:

data-variant=info
data-slots=text
Only HTTP GET and HEAD requests are cacheable. For more information about caching, see RFC-2616 section 13.

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, the application 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.
data-variant=help
data-slots=text
The full list of cache types can be found in the Overview of cache types topic.

Clean cache

To clean cache, run

bin/magento cache:clean <type> <type>

To view the status of the cache, run:

bin/magento cache:status

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

Clean static files cache

You can clean generated static view files in any of the following ways:

data-variant=info
data-slots=text
This option is only available in developer mode. Refer to the static view files overview for more information. For more details about the application modes, see application modes

Clean static files

Besides the cached files, in 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.