Magento 2 Full Page Cache
Bhavesha | Apr 25, 2021 | 8 min read
Overview
To have a server response time for a Magento website less than 0.5 seconds we need to use Full Page Cache. full page cache enabled will result in a fully generated ready to serve page (as good as a static HTML page).
There are different ways to deliver Full Page Cache
- Varnish cache (is recommended for Magento live site)
- Built-in cache
- Lite Speed server cache (commercial solution is to use a lite speed cache server and use its plugin to deliver full page cache for the Magento website)
How to Configure Magento2 Full Page Cache?
Open your Magento admin > System > Cache , management > check
- On the admin sidebar
- Go to Stores > Configuration > Advanced > System > Full Page Cache.
- In the caching Application field, select one of the following
- Built-in Application
- Varnish Caching
- In the TTL (time to live) for the public content field set the time-out for the page cache. The default value is 86400.
How does Magento Full Page Cache Work?
Magento saves a copy of the page with the cache key. The cache key is created using a URL and a few other parameters with some hashing algorithm.
When a new request is made to Magento then the system checks the cached pages for an existing page based on the cache key. If a file exists then that file is delivered, if the file does not exist then the Magento default system works and generates a file and delivers. When this file is delivered the page is also cached.
Magento Full Page Cache command Line
To enable all cache using Magento 2 command line, enter the following command:
-To enable the cache
php bin/magento cache:enable
-To disable the cache
php bin/magento cache:disable
-To clean the cache
php bin/magento cache:clean
– To flush the cache
php bin/magento cache:flush
php bin/magento cache:flush
Cacheable and Non-Cacheable Pages
Cacheable and Uncacheable define whether a page and Block should be cached or not.
Magento2 full-page cache works for most of the pages on your websites.
These are CMS, product, and category pages.
Uncacheable pages are generally pages that contain private customer-specific data
generated on every page load eg. checkout, cart, and customer account page.
What should not be part of the cached page?
There are two types of data: public content and private content.
- Private content – This content is user-specific so should not be a part of a cached page.
- Public content – Any Page or Block that is built on Public content should be cached and delivered via full page cache.
High cache hit ratio in Magento 2
The hit rate refers to the percent of queries returning a cached page ( fast response). If the hit rate is low, most of your users will have to wait for a few seconds for the server to respond and generate the page, which is definitely not what we are looking for. Cache hit ratio should be high, if you’re using Varnish and making sure that cache Cleaning is not very frequent, cache lifetime is properly thought of and cache tags and identifiers are given due consideration then a higher cache hit ratio can be expected. It is also recommended that admin activities should not result in frequent cache cleaning.
If we want that the average server response time to be good then we shall code and configure it to get most of the pages from the Full Page Cache.
Hit rate (%) = [hits from page cache] / [total number of hits] * 100
Magento 2 Full Page Cache Warmer Extension
To achieve a high cache hit ratio we recommend the use of the full page cache warming technique via the use of extensions. Generally, a sitemap is submitted to the cache warming module with some additional configuration to achieve effective cache warming. Also, modules give a lot more insight into what is happening and based on those insights we can fine-tune the module further.
Full Page Cache warming extension is the best solution for a Magento store that significantly improves the average page load time, decreases the load on the server, improves website ranking, and increases sales conversion.
Full cache warming extensions are:
Mirasvit Cache Warmer : https://mirasvit.com/magento-2-extensions/full-page-cache-warmer.html
Amasty Extension : https://amasty.com/full-page-cache-warmer-for-magento-2.html
Magento full page cache: most frequent reason a page is not delivered from the full page cache
- Presence of Non-cacheable block.
- Check that Magento full page cache is enabled
- open your Admin Panel
Go to the System > Cache Management, and check if the Magento full page cache is enabled.
- open your Admin Panel
- Frequent cache flushing due to the category or product updates or some improper cron.
Recommended Alerts when using Full Page cache
- Private data got cached and displayed to other customers.
- The page went Blank or had some error and still was cached.
How to know if you need Full Page Caching :
- Look at your Analytics and get the average server response load time as this will give a proper picture of what the user experience is across a time span.
- Check using extensions/modules
Our Blogs
- Magento Performance Optimization Services
- Guide to Page Speed Metrics
- Speed up Magento 2 The Ultimate Guide
- Magento 2 Speed Optimization: Tips & Techniques
- Optimize Images in Magento 2
- Improving Magento 2 Web Vitals
- Magento 2 TTFB (Time to First Byte) Optimization Guide
- Varnish Cache: the Secret for Boosting Page Speed for Magento
- Use CDN to Speed Up Static Content Delivery
Latest Posts
2 Comments
Leave A Comment
You must be logged in to post a comment.
Very informative practical Blog.
This content is well-detailed and easy to understand. Thank you for creating a good content!