Today, we're going to look at some important elements of Magento 2's Page Cache performance. The aspects we are about to describe below may already be quite familiar to you, however, it's still useful to have a refresher on them from time to time.
Unlike Magento 1, Magento 2 includes an inbuilt Full Page Cache module, which greatly speeds up Magento 2 stores.
In principle, the module repeats M1 Enterprise Page Cache: the page contents are completely cached, but dynamic information is updated through AJAX requests. This technique reduces server response time for regular frontend pages.
Consequently, to configure the correct operation with page cache, all extensions additionally installed on your store need to be assigned to "pay attention" to this peculiarity. This makes sure that updates to dynamic information will be made properly.
Another vital fact to consider is the possibility for caching a page but only if this page excludes not-cacheable blocks.
As time-consuming as it can be to add/monitor/exclude these blocks in the case of a huge store, having functional operations and raised benefits are absolutely well worth it. You can declare a not-cacheable block in layout files by adding the attribute cacheable="false" there.
To summarize, all pages on the following list cannot be cached by default:
- Login/registration/forgot password pages
Customer account pages
Search results pages (beginning from the version 2.2.4, it becomes possible to declare multiple pages to cache them)
- Cart page
- Checkout and also as part of other rarely visited pages
However, the good news is that these key pages that get about 90% of users’ visits are cacheable:
- Home page
- CMS pages
- Products list (category)
- Product details
Let’s take a closer look into the cache operation cycle:
When a page is visited for the first time - the content of the page is generated from scratch and saved in cache with a unique identification.
When this page is subsequently visited in the future, it is "returned" from the cache it was previously added to. This significantly speeds up Magento 2 pages, greatly improving your customer experience, and thus boosting sales.
This cycle is possible if the following two conditions are met:
- The cache lifetime has not yet expired (it is 24 hours by default)
- The previously cached page has not been deleted from the cache; deletion takes place in different cases, but the most basic reasons are a change in related content (category, product) or reindexing.
What is Hit Rate and why it is so important?
Now we are arriving at the most interesting element - a hit rate or hit ratio.
What is this?
To make a long story short, the hit rate refers to the percent of queries returning a cached page (fast response).
i.e. for 100 page openings, if 75 pages were given from page cache, the hit rate is 75%.
Hit rate (%) = [hits from page cache] / [total number of hits] * 100
Consequently, if the hit rate is low, most of your users will have to wait for several seconds for the server to respond, which is decidedly not what we are looking for. Instead, we should be striving to make the rate lean towards 100%.
Unfortunately, Magento 2 does not offer any inbuilt techniques/engines either to monitor Magento 2 performance or to manage the coverage rate indicator.
Based on our experience, we have frequently encountered stores where Full Page Cache does not work at all!
This results from the fact that layout file default.xml, a very popular extension, includes a not-cacheable block and this one completely disables the entire Page Cache.
We offer two tools for Page Cache management and performance enhancement in general:
- The first is the Page Cache Warmer. Besides all other features, it increases the cache coverage rate by proceeding with page warming.
- The second is our new extension named Health Monitoring Suite. It monitors the coverage rate indicator (and many others on top of this), and informs users if there are any negative impacts on your store.
We hope this essay has been useful to you and eagerly await any additional questions and feedback you may have.
Please, don't hesitate to contact us, we are always ready to help you!