1

I know this is seem stupid question but I'm a newbie in Magento 2. So I want to ask you guys that Where can I see a different between cacheable ='false' and cacheable='true'?.

I checked in Local Storage in Chrome but it didn't show me anything different.

2

Let's start at the Magento\Framework\View\Layout::getOutput.
As you may suspect, this transforms the layout to output.
In this method there is a call to renderElement from the same class.
This one renders each element of the page.
In this method, the event core_layout_render_element is dispatched.
And this event is observed by the PageCache module.

<event name="core_layout_render_element">
    <observer name="pagecache" instance="Magento\PageCache\Observer\ProcessLayoutRenderElement" />
</event>

Going to the ProcessLayoutRenderElement::execute method you should find this: if ($this->isFullPageCacheEnabled() && $layout->isCacheable()) {

So if the full page cache is enabled and the layout is cachable some hole punching will happen in the generated HTML.

Now let's focus on $layout->isCacheable().
The method looks like this:

public function isCacheable()
{
    $this->build();
    $cacheableXml = !(bool)count($this->getXml()->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]'));
    return $this->cacheable && $cacheableXml;
}

This means the page layout xml is generated and then Magento looks for a block element in the layout with [@cacheable="false"]. If there is at least one, then the page is not cacheable.

0

You will not see anything different in Local Storage of Chrome, Because in the current context, The block is cached on sever (if cacheable is set to true)

If you want to see the practical difference. leave a comment.

as per your comment, I am giving an example:

1) Go to Stores->configuration->customers->customer configuration->captcha

2) Enable it for login page, refer following settings

enter image description here

3) Enable the cache from admin / using CLI commands.

4) Now go to customer login page and refresh it 4-5 times and see the effect on captcha image.

5) Next open file customer_account_login.xml

6) edit the following code and remove cacheable="false"

<referenceContainer name="form.additional.info">
            <block class="Magento\Captcha\Block\Captcha" name="captcha" after="-" cacheable="false">
                <action method="setFormId">
                    <argument name="formId" xsi:type="string">user_login</argument>
                </action>
                <action method="setImgWidth">
                    <argument name="width" xsi:type="string">230</argument>
                </action>
                <action method="setImgHeight">
                    <argument name="width" xsi:type="string">50</argument>
                </action>
            </block>
        </referenceContainer>

7) Now flush the cache and see the result after again refreshing multiple times. You will see the captcha is not getting changed properly.

  • Yes bro. I just want to see different between it. Can you help me? – Henry Bui Mar 2 '17 at 2:03
0

X-Magento-Cache-Debug: MISS shows that the page is never cached. X-Magento-Cache-Debug: HIT this shows the page is cached.

These can be found in the headers of a request refer : https://www.screencast.com/t/epI3jcPKA

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.