1

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 getStoreConfig inspection 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:

http://cdn.meme.li/i/o5acb.jpg

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.

3

I think it is better to do it next way:

  1. Create observer on post dispatch

  2. Check there if category matches the category in question - set no_cache param 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 Aug 15 '13 at 13:49
  • 1
    But 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 Aug 15 '13 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 Aug 17 '13 at 4:53
  • Is my custom route loading the fpc version after my otedispatch?? – philwinkle Aug 17 '13 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 Aug 18 '13 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.