A page cache is a transparent cache for the pages originating from a secondary storage device such as a hard disk drive (HDD) or a solid-state drive (SSD). To clarify, the page cache is a component that stores data. So future requests for that data can be served more faster.
In Magento 2, a full-page cache module stores the entire HTML code of a generated page in the cache storage. As storage, Magento may use either a simple file system or more sophisticated systems.
When your store visitors opens any page in the browser, their request goes to the Magento 2 page cache system:
- If the requested page is inside a cache storage, it is quickly returned to the visitor. A speed of such an operation is very high.
- If the requested page is not present in the cache storage yet, Magento generates this page, adds it to the cache storage and returns to a customer. The speed of such an operation is much slower.
Page Cache Workflow
We see that if a page is served from the cache, Magento sends a response very fast. If a page is not in the cache, the response is slow.
Why is Page Cache so important?
The correct work of the cache system directly affects the store speed. And the speed influences the store performance in Google search results and conversion of store visitors into buyers.
So the importance of the page cache system is huge and Magento 2 speed optimization is a very important task.
Page cache common issues in Magento 2
The first thing to do when your page goes slow is looking for the slow pages. You need to find such pages in your store and exam them individually using the following steps:
1. Check that Full page cache is enabled
First of all, please, open your Magento admin panel, go to the System > Cache Management and check if the Full page cache is enabled.
It takes a lot of times. When developers did some job on a store, disabled the cache and forgot to enable it back at some point. As a result, the store was working without any cache and slowly.
2. Check if a page is served from the cache
There are two simple ways to check if a page is served from cache or not. You may use the one you consider to be simpler.
a) Check by the response time For instance, you have a page http://store.com/page1.html Open it in your browser. Then, open browser development tools: it will show you the page generation time.
Time to first byte (TTFB)
Add any GET parameter to the end of the URL and open the new URL (e.g. http://store.com/page1.html?random). Write down the page loading time from the developer toolbar, you will need the time for the following comparison. In this case, the page is generated from scratch. So its loading time is high.
Then, open the initial page http://store.com/page1.html and write down the loading time from the developer toolbar. Now the page should be served from the cache. Its loading time should be much smaller than in the previous case. If not, the page is not served from cache. That’s a problem.
b) Check by Magento headers To use this approach, you need to switch your Magento store to dev mode. Probably, it is not possible if your store is in production mode and has heavy traffic. But if you do tests on your dev host, this approach should be fine for you.
To switch your store to dev mode, just run the following command via SSH:
bin/magento deploy:mode:set developer
Then open any page and in developer tools of your browser check the headers of that page (for Chrome you need to open View / Developer / Developers Tools and tab Network).
Magento Page Cache Debug Header
Find the header X-Magento-Cache-Debug. If its value is MISS, then the page is not served from the cache. If its value is HIT, the page is from the cache and should be loaded fast.
How to fix it?
There are different types of cache problems that may happen. Some problems are pretty easy. Hence others need a careful approach and developer debugging.
However, from our experience, in 90% of cases, a page is not added to the cache (and cache is not working for that page). Because of uncacheable blocks presence somewhere inside the page. If all your pages are not added to the cache, you have uncacheable blocks globally defined. And they disable your full page cache system entirely.
To fix this cache problem, you need to find incorrect uncacheable blocks and remove or fix them.
All blocks are defined in the layout files, which are placed in the following folders:
There are a lot of files inside those folders. It’s very time consuming to check each file manually to find the issue. So we created a set of commands that will greatly speed up the process.
You can search uncacheable blocks using the following SSH commands:
cd app/design/frontend/ && grep --recursive -l 'cacheable="false"' * && cd ../../..; cd app/code && grep --recursive -l 'cacheable="false"' * && cd ../..; cd vendor && grep --recursive -l 'cacheable="false"' * && cd ..;
Magento 2 Page Cache greatly improves the speed of the store. Your store should be correctly developed and use ‘cache-friendly’ extensions to use all the potential of the Magento cache system.
Try out some Magento 2 extensions from Magesolution to optimize your website!
From our experience, in most cases, page cache is not working because of the presence of globally defined uncached blocks. To spot and fix such blocks, you can follow this post tips. As a result, after solving the issues with your Full page cache you will see a great improvement in the speed of your store.
Don’t forget that the store speed may affect your Google search results and, thus boost the number of visitors and buyers.
Level up your website with ArrowHiTech – official partner of Magento
Our own Magento development support services is plus the option for monthly support packages. It is to make sure your online business always remains in top form. And of course, there are countless other developer websites that can be easily found and perused as well, especially push your Magento 2 site speed.
- Headquarter: Vietnam
- Website: https://www.arrowhitech.com/
- Contact: firstname.lastname@example.org
ArrowHiTech Development Agency
Our Magento 2 Products:
With over 12 years of operation, ArrowHiTech is official Magento’s partner. We has increasingly widened our skills and resources to meet all the requirements of customers all over the world on Web design and development with flexible and reasonable price.
Our Magento services: