category oscprofessionals - Blogs - Magento 2 full page cache

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
  1. On the admin sidebar
  2. Go to Stores > Configuration > Advanced > System > Full Page Cache.
  3. In the caching Application field, select one of the following
    • Built-in Application
    • Varnish Caching
  4. In the TTL (time to live) for the public content field set the time-out for the page cache. The default value is 86400.
page-cache-1

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

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:

Magento full page cache: most frequent reason a page is not delivered from the full page cache

  1. Presence of Non-cacheable block.
  2. 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.
  3. Frequent cache flushing due to the category or product updates or some improper cron.

Recommended Alerts when using Full Page cache

  1. Private data got cached and displayed to other customers.
  2. The page went Blank or had some error and still was cached.

How to know if you need Full Page Caching :

  1. 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.
  2. Check using extensions/modules

Latest Posts

2 Comments

  1. John April 28, 2022 at 6:39 am

    Very informative practical Blog.

  2. CMARIX TechnoLab July 7, 2022 at 6:38 am

    This content is well-detailed and easy to understand. Thank you for creating a good content!

Leave A Comment