1

Hello i want to firstly disable cache while backup & after complete it again enable cache. how to do that kindly reply me

1
  • can you check this.
    – Amit Bera
    Sep 4, 2014 at 6:48

1 Answer 1

4

for try clear cache this

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

Mass action for disable for cache try this

   $allTypes = Mage::app()->useCache();
    $types=array('config','layout','block_html','translate','collections','eav','config_api','config_api2');

        $updatedTypes = 0;
        foreach ($types as $code) {
            if (!empty($allTypes[$code])) {
                $allTypes[$code] = 0;
                $updatedTypes++;
            }
            $tags = Mage::app()->getCacheInstance()->cleanType($code);
        }
        if ($updatedTypes > 0) {
            Mage::app()->saveUseCache($allTypes);
        }

Here $types array define type of cache

for enable cache:

$types=array('config','layout','block_html','translate','collections','eav','config_api','config_api2');
    $allTypes = Mage::app()->useCache();

    $updatedTypes = 0;
    foreach ($types as $code) {
        if (empty($allTypes[$code])) {
            $allTypes[$code] = 1;
            $updatedTypes++;
        }
    }
    if ($updatedTypes > 0) {
        Mage::app()->saveUseCache($allTypes);
    }

You can clean cache by Mage::app()->getCacheInstance()->cleanType($type); here type means:

config Or layout Or block_html Or translate Or collections Or eav Or config_api Or config_api2

Mage::app()->getCacheInstance()->getTypes(); this code is provide us list of cache which is i have save in array $types.

4
  • 1
    Nice, but instead of hard coding the cache types you can use this $types = Mage::app()->getCacheInstance()->getTypes();. It's safer in case you have other custom cache types.
    – Marius
    Sep 4, 2014 at 6:14
  • let me check...
    – Amit Bera
    Sep 4, 2014 at 6:21
  • 1
    Please do, but so you know, this is the way the cache types are retrieved for displaying in the grid. See Mage_Adminhtml_Block_Cache_Grid::_prepareCollection
    – Marius
    Sep 4, 2014 at 6:23
  • then offsource you can used this.
    – Amit Bera
    Sep 4, 2014 at 6:24

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.