The question:
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.
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.
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
You can disable block to cache by layout xml code.
See below example code for disable block from cache.
<block class="MagentoFrameworkViewElementTemplate" template="sample:module::sampletemplate.phtml" name="sampleblock" cacheable="false" />
cacheable=”false” is use for that. you can disable like this.
Method 2
From
cacheable=”false” will create uncacheable page, not just block.
For private content you should be using approach described in here:
- http://devdocs.magento.com/guides/v2.1/config-guide/cache/cache-priv-priv.html
- this page also says that using _isScopePrivate is deprecated.
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0