How to temporarily disable cache for Magento scripts

If you are running Magento scripts that are bootstrapped for reasons such as asynchronous processing, syncs, indexing, etc, then you’ll want to disable all Magento cache when Magento is loaded. This will avoid cases where old model data is being used, especially when you have two executions of the Magento script running at the same time.

To disable all Magento cache programmatically add the “global_ban_use_cache” option to your Mage::app initialization. Your Mage::app initialization would look like this:

Mage::app(‘admin’, ‘store’, array(‘global_ban_use_cache’=>true));

Any modules you have running that also use the native Magento cache system should also stop using cache when this flag is set.

Hope this helps some people!

Advertisements

One thought on “How to temporarily disable cache for Magento scripts

  1. Exactly the code I needed today!
    thx Jay!

    When enabling again you may need to Re-init the cache:
    Mage::getConfig()->getOptions()->setData(‘global_ban_use_cache’, FALSE);
    Mage::app()->baseInit(array()); // Re-init cache

    When will you visit us in Switzerland?
    Cheers Rafi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s