2

For some reason I want to disable Full Page Cache for CMS pages including Home Page.
I have created my custom module for this but some reason it is not working.
config.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Custom_HeaderFix>
 <version>1.0.0</version>
 </Custom_HeaderFix>
 </modules>
 <global>
 <models>
 <headerFix>
 <class>Custom_HeaderFix_Model</class>
 </headerFix>
 </models>
 </global>
 <frontend>
 <events>
 <controller_action_predispatch_cms>
 <observers>
 <headerCache>
 <type>singleton</type>
 <class>headerFix/observer</class>
 <method>processPreDispatch</method>
 </headerCache>
 </observers>
 </controller_action_predispatch_cms>
 </events>
 </frontend>
</config>


Observer.php

<?php
class Custom_HeaderFix_Model_Observer {
 public function processPreDispatch(Varien_Event_Observer $observer) {
 $action = $observer->getEvent()->getControllerAction();
 if ($action instanceof Mage_Cms_PageController) {
 $cache = Mage::app()->getCacheInstance();
 // Tell Magento to 'ban' the use of FPC for this request
 $cache->banUse('full_page');
 }
 }
}

My code is working on CMS pages but not for home page

Fabian Schmengler
66.2k25 gold badges191 silver badges422 bronze badges
asked Jul 7, 2015 at 11:18

2 Answers 2

1

If it works for all pages, except the home page, you should replace

if ($action instanceof Mage_Cms_PageController)

with

if ($action instanceof Mage_Cms_PageController
 || $action instanceof Mage_Cms_IndexController) 
answered Jul 7, 2015 at 11:44
3
  • Ahh what a poor mistake by me, how can I forget cms page and home page controllers are different. Commented Jul 7, 2015 at 11:48
  • How can I remove only the header from FPC Commented Jul 7, 2015 at 12:41
  • Holepunching with cache.xml: techytalk.info/… Commented Jul 7, 2015 at 12:43
0

The full page cache uses the event controller_action_predispatch as well and its observer will be executed first because core modules are always loaded before local modules.

I see two possible solutions:

  1. use an event that is triggered before, like controller_front_init_routers - the problem here is that the controller action is not determined yet so you'll have to use the routers' matching methods. This probably makes the page load remarkably slower

  2. Rewrite the full page cache observer pagecache/observer and override processPreDispatch() to check for the controller action before calling the parent method.

answered Jul 7, 2015 at 11:37
1
  • I will try your code. But my code is working on CMS pages but not for home page. Commented Jul 7, 2015 at 11:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.