Kostanos
Kostanos

Reputation: 10434

Magento disable cache from database

There is a way to disable cache from System->Cache Management menu.

How can I do the same without entering to site, using Database SQL query?

Upvotes: 16

Views: 31281

Answers (5)

Fabian Schmengler
Fabian Schmengler

Reputation: 24576

Here is a simple code snippet that can be used in a setup script to enable or disable single cache types:

$cacheOptions = Mage::app()->useCache();

// disable full page cache:
$cacheOptions['full_page'] = 0;

// enable block cache:
$cacheOptions['block_html'] = 1;

Mage::app()->saveUseCache($cacheOptions);

You can look up the cache types in the core_cache_option database table:

mysql> select * from core_cache_option;
+-------------+-------+
| code        | value |
+-------------+-------+
| block_html  |     1 |
| collections |     1 |
| config      |     1 |
| config_api  |     1 |
| config_api2 |     1 |
| eav         |     1 |
| full_page   |     0 |
| layout      |     1 |
| translate   |     1 |
+-------------+-------+
9 rows in set (0.00 sec)

Upvotes: 4

Roger Getnoticed
Roger Getnoticed

Reputation: 21

If you still use the default crappy filesystem cache (A.K.A Architectural facepalm hider) you will notice a file in your cache called: mage---687_CORE_CACHE_OPTIONS and a file called: mage---internal-metadatas---687_CORE_CACHE_OPTIONS. It's under mage--4, if you stick to the defaults.

So there is no need to flush your whole site, if you only need to delete 2 of them. The best to do ofcourse is just ask Magento to remove them, because you can also have XCache or for the professional people a complete rackspace full of no-sql-db's.

Mage::app()->cleanCache(array('MAGE'));

With: Mage::app()->saveUseCache($cacheSettings); it's not needed it will remove it automaticly.

So, the 'rm -rf var/cache/' only will work on a NOOB system. And can crash a Magento system, but the chances are very low. You need a lot of traffic for that, and you can have that with the default filesystem caching system.

Upvotes: 0

Sean Grueboeck
Sean Grueboeck

Reputation: 71

I created a Shell Script to enable, disable and/or clean the magento cache. It reads the necessary parameters (DBHost, etc.) from etc/local.xml...

You can download it from my github gist: https://gist.github.com/seangreen/d9557726b479e066d71f

The actual mysql queries are such:

Disable Cache: mysql -h $DBHOST -u $DBUSER -p$DBPASS -e "UPDATE core_cache_option SET value=0;" $DBNAME

Enable Cache: mysql -h $DBHOST -u $DBUSER -p$DBPASS -e "UPDATE core_cache_option SET value=1;" $DBNAME

And after disabling or enabling it's good to clean the cache: rm -rf var/cache/*

Upvotes: 1

Kostanos
Kostanos

Reputation: 10434

The easiest way to disable cache is by using SQL query:

UPDATE `core_cache_option` SET value=0;

And clear your cache folder just to be sure:

rm -rf <YOUR SITE PATH HERE>/magento/var/cache/*

In Magento Enterprise Edition you also have to clear the full_page_cache directory (thanks to Bartosz Górski):

rm -rf [YOUR SITE PATH HERE]/magento/var/full_page_cache/*

Upvotes: 31

liyakat
liyakat

Reputation: 11853

if your dont want to login to site just use below script to make it possible

<?php

$mageFilename = 'app/Mage.php';

require_once $mageFilename;

umask(0);
Mage::app('admin');

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

$types = Array(
          0 => 'config', 
          1 => 'layout',
          2 => 'block_html', 
          3 => 'translate', 
          4 => 'collections',
          5 => 'eav',
          6 => 'config_api',
          7 => 'fullpage',
          8=>'config_api2'
        );

 $allTypes = Mage::app()->useCache();

$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);
    echo "Caches disabled Programmatically";
}
else {
    echo "Caches disabled Already";
}

just create your own script and your will done with your cache part

hope this will sure help you.

Upvotes: 6

Related Questions