I found an interesting workaround for an issue I was having; not sure if it's best-practice, but I was wondering if someone could explain to me how this works:
- I needed to provide a check on postdispatch for a category load
- Created an observer, inspect the
Mage::registry('current_category') - If the category matches the category in question, I do some
getStoreConfiginspection to a custom module, and based on the return, I either do nothing (let the request sail through) or redirect to another page
What I found is that with Enterprise Full Page Cache enabled, my postdispatch event was never firing.
Which raises the question:
(source: meme.li)
My solution:
In my custom module's controller I created a new action which effectively just calls $this->_forward() to the category as before. But now, instead of FPC intercepting my event, the event is fired correctly.
My question:
Is this poor practice?
Is there a better suggested workaround?
It seems less "hacky" than fully disabling FPC for the category in question... though that may have been the actual result of the _forward. The end-user experience is seamless and all category features work as-expected from there including pagination, layered navigation.
1 Answer 1
I think it is better to do it next way:
Create observer on post dispatch
Check there if category matches the category in question - set
no_cacheparam into the request:$request = $observer->getEvent()->getControllerAction()->getRequest(); $request->setParam('no_cache', true);
(see Enterprise_PageCache_Model_Observer::checkCategoryState()). So, only categories which should be redirected won't be cached by FPC.
-
This was my first attempt - the problem I'm having is that the observer never fires once the FPC has stored the page. Maybe it's a chicken-and-egg sort of problem? Any thoughts why postdispatch doesn't fire on direct requests when FPC is involved?philwinkle– philwinkle2013年08月15日 13:49:55 +00:00Commented Aug 15, 2013 at 13:49
-
1But category won't be cached by FPC with
$request->setParam('no_cache', true);, so each time your observer should be fired again and again. Are you sure page is still cached with'no_cache' => true?Dmytro Zavalkin– Dmytro Zavalkin2013年08月15日 14:10:14 +00:00Commented Aug 15, 2013 at 14:10 -
@philwinkle if the page has been cached, Magento's routing system is not loaded, and thus those events are not fired. If you must rely on getting them, then you need to prevent it from being cached by FPC and/or varnish if used.davidalger– davidalger2013年08月17日 04:53:42 +00:00Commented Aug 17, 2013 at 4:53
-
Is my custom route loading the fpc version after my otedispatch??philwinkle– philwinkle2013年08月17日 05:07:03 +00:00Commented Aug 17, 2013 at 5:07
-
OK I understand now. Having messed around with it, my particular approach was (mistakenly) the correct approach for my particular situation - a custom module route that mirrors a category page under extreme peak during a television appearance. My custom route would not cache, so it fires events. However the _forward does pull the FPC version of the catalog page. However, this is not the usual application for this type of situation. I will accept your answer because I think that it addresses the actual question at-hand. Thanks!philwinkle– philwinkle2013年08月18日 00:30:00 +00:00Commented Aug 18, 2013 at 0:30