Website speed is a crucial factor for ranking high in SERP, getting new customers, and improving conversion rates in general. It is also extremely relevant to the overall experience of your customers.

While website speed influences a lot of things, multiple factors slow it down which requires your attention constantly.

The one we want to cover today is Magento 2 full page cache that is provided by default.

In this guide, you'll learn everything you need to know about Magento 2 full page cache and how it works. It will enable you to improve Magento website performance with the free caching solution Magento goes with.

Post Contents [hide]

    Let's start with the basics.

    What is Full Page Cache in Magento 2?

    Magento 2 full page cache is the free built-in Magento 2 caching solution that allows you to reduce the server load time and improves the response time due to the fast loading of CMS, product, and catalog pages.

    As we've just mentioned, the full page cache is enabled in Magento 2 by default due to the PHP reverse proxy that is an intermediary between your website visitors and your installation. It reduces your server load time and allows you to save on bandwidth.

    How Does Magento Full Page Cache Work?

    Once you enter a website page, you trigger a request to the server to generate the page content which takes some time. The system doesn't store the latest version of the page and has to regenerate the page every time someone enters a page.

    To avoid this Magento stores the copy of the page with the cache key in the system after the first-page load. This way the page content that matches the identity of the first cached copy is rendered way faster the second time you enter the page.

    How Does Magento Full Page Cache Work?

    It is how the Magento full page cache works from the server side. When it comes to the customer side it is a bit different.

    User access your website through a browser on their laptop or PC. Correspondingly, the data is processed on their devices. To cache the content on the client-side Magento provides the page-cache.js file that processed the cache on customers' devices and synchronizes them with the server.

    However, there is even more to it.

    Full Page Cache Session Types

    Customers come to your website to perform different actions: just casually look for some new products, compare them and create a wishlist to make a purchase. So, correspondingly you can't cache the same content for all of them. In this case, Magento defined different session types to cache content for different visitor sessions.

    There are 3 types of visits that are used for different kinds of requests for caching purposes:

    • Non-sessioned — visitors browse the website pages, but don't interact with them. So the system caches the page content for the other non-sessioned visitors and displays it for each viewed page.
    • Sessioned — visitors browse the website pages and conduct different actions like adding products to the shopping cart or comparing them. Each session is assigned a session ID and all cached pages are displayed only to those sessioned visitors.
    • Customer — sessions are performed by the logged-in users who browse and shop on your store. Besides, they are displayed special offers, prices, and promotions specified for their customer group.

    Cacheable and Uncacheable Pages

    Cacheable and uncacheable define whether a page should be cached.

    Magento 2 full page cache works for all pages on your website so all of them are cacheable by default. Those are the CMS, product, category, and other catalog pages. Uncacheable pages, on the other hand, are pages that contain private data generated every page load e.g. checkout and customer account pages.

    To make the page uncacheable you just have to mark the page block with cacheable="false" like in the example:

    <block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Magento_Customer::form/edit.phtml" cacheable="false">
        <container name="form.additional.info" as="form_additional_info"/>
    </block>

    However, please note that if any of the blocks in a layout is marked as uncacheable, the whole page will be considered as such. It can negatively result in your website performance. Moreover, you should never make any of the content pages uncacheable.

    Private vs Public Content

    Depending on the caching methods and kinds of pages cached, there define different content types: public and private.

    • Public content — static content with a long life span that is stored on the server-side and is available for multiple users (contact us, about us, category listing, product page, etc.).
    • Private content — dynamic content with a short life span that is stored on the client-side and is available for specific users (customer data, personalized sales offer, shopping cart, wishlist, etc.).

    Private and Public Content in Magento 2

    Enabling full page cache for Magento you make sure to provide relevant content to your customers as fast as possible.

    So, let's find out how to configure it in Magento 2.

    How to Configure Full Page Cache in Magento 2?

    1. Go to Stores > Configuration > Advanced > System > Full Page Cache.
    2.  Select the Caching Application: Built-in Application or Varnish Caching.
    3. Set the TTL for public content to define the timeout for the page cache. It is set to 86400 by default which is approximately 24 hours. After the time expires, page data is updated.

    Magento 2 Full-Page Cache Configuration

    In case you want to use Varnish for your application, you have to fill out additional fields.

    Configure Varnish in Magento 2

    1. Enter IP addresses that can purge the generation of a config file by Varnish in the Assess list field.
    2. Set the backend host used to generate config files in the Backend host.
    3. Define the Backend port for config file generation.
    4. Specify the Grace period in seconds to generate config files.
    5. Export Сonfiguration for your version of varnish.

    Magento Varnish Configuration

    Monitor Magento 2 Full Page Cache

    Sometimes when you notice a sudden drop in performance, it might be that the full page cache is disabled. It negatively influences not only your store performance but the workflow of the backend as well.

    To monitor the full page cache and enable it when needed, configure the disabled cache notification.

    Disabled Full-Page Cache Magento

    The other option is to set up the Cache Warmer that will simulate user behavior and warm the cache on your store. In the meantime, no complex configuration is required. Just configure the basics and the full page cache will be taken care of.

    To save you from monotonous browsing through the multitude of modules we prepared an overview of the best Magento 2 Full Page Cache Warmer Extensions on the web. Check them out to deliver content to your customers faster with the right caching solution.