2

I am having a strange issue regarding built-in FPC in magento2.

I have a custom module, in its index controller, it just renders a phtml file. This phtml file shows some information retrieving it from a custom table. This is just a simple thing that I have done here.

The problem is when I disable FPC in magento 2 the contents are displayed correctly, but when I enable the FPC than it renders the blank page .

See below two screeshot for the scenario analysis. Blank data when cache is enabled

Data when FPC is disabled

Ok so what I have tried till now.

I read somewhere that including below code on block construct function excludes the block from FPC.

public function __construct(){
$this->_isScopePrivate = true;
} 

But it didn't worked.

What i want?

I want to exclude my module from FPC.

Can anyone help me or enlight with some insights?

Thanks.

  • If you want to disable your module from FPC, you can it from layout xml file but there is disable full page disable from FPC. it is not correct way. – Suresh Chikani Nov 17 '16 at 6:14
  • sorry i don't understand what are you suggesting here. How can i do it from layout xml. Can you show some codes? – aton1004 Nov 17 '16 at 6:16
1

You can disable block to cache by layout xml code.

See below example code for disable block from cache.

<block class="\Magento\Framework\View\Element\Template" template="sample:module::sampletemplate.phtml" name="sampleblock" cacheable="false" />

cacheable="false" is use for that. you can disable like this.

  • This doesn't uncache the whole module Url's but this option works for me so i am accepting it.Thanks. By the way if i have a block called inside a static block, this trick is not working, do you have anything else for that case in mind? – aton1004 Nov 17 '16 at 11:36
  • add your code which you have try it in static block. – Suresh Chikani Nov 17 '16 at 11:41
  • yes i added the cacheable="false" on block inside the static block but it is not working. – aton1004 Nov 17 '16 at 12:10
  • this solution worked for me magento.stackexchange.com/questions/103256/… – Lead Developer Dec 1 '16 at 11:12
  • 2
    cacheable="false" disables caching for the whole page! This is NOT a proper solution, but a HUGE performance degradation recipe. Please read inviqa.com/blog/how-full-page-cache-works-magento-2 – Dmitri Sologoubenko Jan 30 '17 at 12:36
2

From

cacheable="false" will create uncacheable page, not just block.

For private content you should be using approach described in here:

You can check my answer also here why not to use cacheable="false" a bit more in details: https://magento.stackexchange.com/a/163875/4899

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.