Angel Wong
Angel Wong

Reputation: 81

Magento Flush Block Cache

In Magento CE 1.4.1.1, I have added block cache to product view page. So the frontend product page will be cached after first visit, so far so good.

however, I found that even if someone purchased that product, the block cache was not flushed. This is not good because then in the frontend, the product page will show wrong inventory/stock information, also no way to show alert message once the product page is cached. (seems like the product block cache is only flushed when I save the product in backend admin)

1) any expert can show how to flush the block cache for a particular product?

2) along the same line, if I want to cache category page since I am using ajax layered navigation (and ajax paging, ajax sort order), how to add exclude cache condition on the above areas?

Thanks

Upvotes: 0

Views: 1115

Answers (1)

MagePal Extensions
MagePal Extensions

Reputation: 17656

It is hard to say how to achieve this without seeing your code and knowing how your page cache is implemented, but on possible solution is to create an observer that will clear cache for all products ordered

In /app/code/local/MageIgniter/ClearProductCache/etc/config.xml

....
    <events>
        <sales_order_place_after>
            <observers>
                <clearproductcache>
                    <type>singleton</type>
                    <class>clearproductcache/observer</class>
                    <method>implementClearProductCache</method>
                </clearproductcache>
            </observers>
        </sales_order_place_after>
 ....

In /app/code/local/MageIgniter/ClearProductCache/Model/Observer.php

<?php
class MageIgniter_ClearProductCache_Model_Observer 
{
    public function implementClearProductCache($event)
    {

        $_order = $event->getOrder();

        foreach ($_order->getAllItems() as $item) {
            //call function to clear cahced
            //$item->getId();
       }


        return $this;
    }

See Implementing observer Magento

Upvotes: 0

Related Questions