Magento cache overview
Caching is one of the most effective ways to improve website performance. Generally speaking, there are two methods of caching content:
- Client-side (browser)
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 Magento 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 Magento’s 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.) 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
Examples of uncacheable pages include the compare products, cart, checkout pages, and so on.
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 Magento websites generate dynamic and personalized “private” content that should only be served to one user, which presents unique caching challenges. To address these challenges, Magento 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.
The following cache types mostly have impact on frontend development process:
|Cache type “friendly” name||Cache type code name||Description|
||Compiled page layouts (that is, the layout components from all components). Clean or flush this cache type after modifying layout files.|
|Block HTML output||
||HTML page fragments per block. Clean or flush this cache type after modifying the view layer.|
||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.|
||Merged translations from all modules.|
The full list of cache types can be found in the Overview of cache types topic.
To clean cache, run
1 magento cache:clean <type> ... <type>
To view the status of the cache, run:
1 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:
This option is only available in
developermode. Refer to the static view files overview for more information.
Manually by clearing the
var/view_preprocesseddirectories and subdirectories except for
To clear the
pub/staticdirectory of all files except
.htaccess(which is a hidden file), enter the following command:
rm -R pub/static/*
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
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