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
-
You don't need the code in the settings of the CMS page and you definitely should not modify Mage_Cms_Controller_Router as that is modifying core (a big no-no). You need to create your own module and put that XML content in the config.xml for the module.Joe Constant– Joe Constant2015年01月30日 21:21:23 +00:00Commented Jan 30, 2015 at 21:21
-
thank you but I don't have a module I just have a phtml page so you mean I should create a distinct module?Nickool– Nickool2015年01月30日 21:23:07 +00:00Commented Jan 30, 2015 at 21:23
-
Yes. You have to create a distinct module. You should never modify core filesJoe Constant– Joe Constant2015年01月30日 21:24:35 +00:00Commented Jan 30, 2015 at 21:24
-
yes i know i shouldn't change core but i always change core and if it worked i will clear them and override by local because i'm lazyNickool– Nickool2015年01月30日 21:25:26 +00:00Commented Jan 30, 2015 at 21:25
-
Thank you Joel,I really appreciate I will do the module creation and keep up to see if I can do it. I am so frustratedNickool– Nickool2015年01月30日 21:28:42 +00:00Commented Jan 30, 2015 at 21:28
1 Answer 1
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');
}
}
-
ok I was wrong my cache was disabled and still i have problemNickool– Nickool2015年01月30日 22:44:18 +00:00Commented Jan 30, 2015 at 22:44
-
Please update your question to provide more details about your custom module.Joe Constant– Joe Constant2015年01月31日 06:59:59 +00:00Commented Jan 31, 2015 at 6:59
-
magento.stackexchange.com/questions/54192/…Nickool– Nickool2015年02月02日 16:39:33 +00:00Commented Feb 2, 2015 at 16:39
-
I updated here and also ask again question to clarifyNickool– Nickool2015年02月02日 17:14:35 +00:00Commented Feb 2, 2015 at 17:14
-
I assume you also added a module XML under app/etc/modules correct?Joe Constant– Joe Constant2015年02月03日 17:06:55 +00:00Commented Feb 3, 2015 at 17:06
Explore related questions
See similar questions with these tags.