Magento 2 – Exclude Custom Module from Full Page Cache

cachemagento-2.1magento2

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.

Best Answer

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.