Page caching
Caching is one of the most effective ways to improve website performance. Generally speaking, there are two methods of caching content:
- Client-side (browser)
- Server-side
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.
data-variant=warning
data-slots=text
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:
-
Public - Public content is stored server side in your reverse proxy cache storage (e.g., file system, database, Redis, or Varnish) and is available to multiple customers. Examples of public content include header, footer, and category listing.
-
Private - Private content is stored client side (e.g., browser) and is specific to an individual customer. Examples of private content include wishlist, shopping cart, customer name, and address. You should limit stored private content to a small portion of the page's total content.
data-variant=info
data-slots=text
Cache types
The following cache types mostly have impact on frontend development process:
layoutblock_htmlfull_pagetranslatedata-variant=help
data-slots=text
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:
- In the Admin. Go to System > Tools > Cache Management and click Flush Static Files Cache.
data-variant=info
data-slots=text
developer mode. Refer to the static view files overview for more information. For more details about the application modes, see application modes-
Manually by clearing the
pub/staticandvar/view_preprocesseddirectories and subdirectories except forpub/static/.htaccess.To clear the
pub/staticdirectory of all files except.htaccess(which is a hidden file), enter the following command:rm -r pub/static/*/*To clear the
var/view_preprocessed, enter the following command:rm -r var/view_preprocessed/* -
Several commands support an optional parameter
--clear-static-content, which cleans generated static view files:
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.