在单页上禁用/绕过Magento全页缓存
如何为单个页面禁用或绕过FPC?我不想使用打孔,因为页面上有几个需要动态处理的块,我宁愿修改一个config/class来指定不应该缓存整个页面(类似于签出的行为) ).
How can I disable or bypass FPC for a single page? I don't want to use hole-punching as there are several blocks on the page that I need to be dynamic and I would rather modify one config/class to specify that the entire page should not be cached (similar to the behavior of checkout).
我对FPC的理解是,它不用于会话用户"(已登录,已添加到购物车等).但是,我看到FPC会在用户登录时影响页面.如果禁用FPC,则该页面可以正常工作.
My understanding of FPC was that it was not used for "session users" (logged in, added to cart, etc...). However, I'm seeing FPC affect pages when a user is logged in. If I disable FPC, then the page works as desired.
这是为特定控制器禁用FPC的解决方案(也可以扩展到特定操作).
Here is the solution for disabling FPC for a specific controller (could be extended to specific action as well).
首先创建一个观察者以监听controller_action_predispatch
事件:
First create an Observer to listen on the controller_action_predispatch
event:
public function processPreDispatch(Varien_Event_Observer $observer)
{
$action = $observer->getEvent()->getControllerAction();
// Check to see if $action is a Product controller
if ($action instanceof Mage_Catalog_ProductController) {
$cache = Mage::app()->getCacheInstance();
// Tell Magento to 'ban' the use of FPC for this request
$cache->banUse('full_page');
}
}
然后将以下内容添加到模块的config.xml
文件中. <frontend>
部分:
Then add the following to your config.xml
file for the module. This goes in the <frontend>
section:
<events>
<controller_action_predispatch>
<observers>
<YOUR_UNIQUE_IDENTIFIER>
<class>YOURMODULE/observer</class>
<method>processPreDispatch</method>
</YOUR_UNIQUE_IDENTIFIER>
</observers>
</controller_action_predispatch>
</events>
现在,Magento每次都会提供您的页面,并绕过FPC进行请求.
Now Magento will serve up your page every time and bypass FPC for the request.