Magento – how to disable cache for a CMS page

cachecmsconfigurationfull-page-cachelayout

I want to disable the cache for a particular CMS page I have hours and hours search through the internet and gained nothing. I know that an observer load pages and so i can ban cache for the particular page but I don't know exactley how to do that. I have seen this problem and the solution

I didn't know how to relate it to CMS pages so I went to the controller of the CMS page:
Mage_Cms_Controller_Router

and I wrote this function:

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');
    }
}

then in the setting of the cms page layout update I did the following:
enter image description here

which is:

<config>
<frontend>
<events>
    <controller_action_predispatch>
        <observers>
            <page_cms_myid>
                <class>Mage_Cms_Controller_Router</class>
                <method>processPreDispatch</method>
            </page_cms_myid>
        </observers>
    </controller_action_predispatch>
</events>
</frontend>
</config>

this is not working and still the cache of the page is enabled.
I really need help

UPDATE:I created the module with two pages observer.php and config.xml:

<?php
class SmashingMagazine_LogProductUpdate_Model_Observer
{
    Mage::log("test here");
public function processPreDispatch(Varien_Event_Observer $observer)
{
    $action = $observer->getEvent()->getControllerAction();

    // Check to see if $action is a Product controller
    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');
    }
}
    public function logUpdate(Varien_Event_Observer $observer)
    {
        $product = $observer->getEvent()->getProduct();
        $name = $product->getName();
        $sku = $product->getSku();

        Mage::log("{$name} ({$sku}) updated", null, 'product-updates.log');
    }
}

config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <SmashingMagazine_LogProductUpdate>
            <version>0.0.1</version>
        </SmashingMagazine_LogProductUpdate>
    </modules>
    <global>
        <models>
            <smashingmagazine_logproductupdate>
                <class>SmashingMagazine_LogProductUpdate_Model</class>
            </smashingmagazine_logproductupdate>
        </models>
        <events>
        <controller_action_predispatch>
        <observers>
            <page_cms_myid>
                <class>SmashingMagazine_LogProductUpdate_Model_Observer</class>
                <method>processPreDispatch</method>
            </page_cms_myid>
        </observers>
    </controller_action_predispatch>
        </events>
    </global>
</config>

but how to add the custom module to the CMS page

Best Answer

You have already found your solution. You are just a few steps off. The answer is indeed the same as: https://stackoverflow.com/questions/8405232/disable-bypass-magento-full-page-cache-on-single-page.

You need to see if the action is an instance of the CMS controller. Then you need to check to see if the page being requested is the one you want to not cache.

1-create the module

2- insert xml in config.xml

3- insert the function in your observer

public function processPreDispatch(Varien_Event_Observer $observer)
{
    $action = $observer->getEvent()->getControllerAction();

    // Check to see if $action is a Product controller
    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');
    }
}