Magento 2 – Why Full Page Not Cached Even if FPC is Enabled?

full-page-cachemagento2varnish

I am using Magento EE 2.1.1 and FPC is enabled (built-in).

What I suppose is, if any page(homepage, category or product pages) is accessed next time, Magento should dispatch whole page content from the cache. But this is not happening. I can see many individual blocks are getting rendered.

Can anyone shed some light on it, please?

  • Is it normal behaviour? or a bug in Magento EE 2.1.1
  • Will full page only be cached in the case of Varnish instead of built-in FPC?

NOTE: The value of HTTP header X-Magento-Cache-Debug is always MISS

Best Answer

Most common issue is a block included in all pages with cacheable = false. Maybe an extension with this declaration in default.xml. See vendor/magento/framework/View/Layout.php, function isCacheable.

In particular:

`$this->getXml()->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]')`

To debug page load and save, see bellow. But before it, I would start with the above.

The page is loaded/saved from page cache type with these entry points:

vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php

vendor/magento/module-page-cache/Model/Controller/Result/BuiltinPlugin.php

This class is an around plugin on vendor/magento/framework/View/Result/Layout.php , renderResult function. Layout is a more complex version of vendor/magento/framework/Controller/Result/Raw.php. Raw builds a page in a string ($content = 'All that it is';). Layout builds the page using XML layout (a tree of blocks/ a tree of strings).

All plugins contain straight forward code and there is no need for further code explanation. Cache is HIT when the page is found in cache. If not in cache, than it allows the application to build the content (html; there is a check that JSON should not be cached, ..) and saves in cache page's html for the next time.

In the 2 plugins (FrontController mostly) you can start debugging and see when it fails. The cause of your issue will be exposed by other parts of the code and to me it looks like it's caused by your setup.

If anything, there is a fix in Kernel.php https://github.com/magento/magento2/commit/861f596371825d9e24672cd613229ae9486c635f I personally find it odd.

Related Topic