0

Clean the cache in magento

 Mage::app()->getCacheInstance()->clean();

1 . How the above code will work ? it will remove all the cache or any particular instance or page. suppose I will add this code on any block initialization code like below.

class Fishpig_Wordpress_Block_Sidebar_Widget_Menu
{
    /**
     * Generate the Menu HTML
     *
     * @return $this
     */
    public function _beforeToHtml()
    {
        parent::_beforeToHtml();

        Mage::app()->getCacheInstance()->clean();
        $menuBlock = $this->getLayout()->createBlock('wordpress/menu')
            ->setMenuId($this->getNavMenu())
            ->includeWrapper(true);

        $this->setMenuBlock($menuBlock)
            ->setMenuHtml($menuBlock->toHtml())
            ->setTitle($menuBlock->getTitle());

        return $this;
    }
}
1

It will clear all the cache types, the same as if you'd checked all the cache types under "Cache Management" - see this question for details.

If you put that into your block initialization code, you'll be clearing your cache every time Magento runs that code... might not be ideal!

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.