Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Clear Magento's Caching of its DB Schema?

I'm developing a Magento extension that introduces a new table to the DB. Whenever I release a new version of the extension that makes modifications to the table schema, I find that users are forced to manually click the "Flush Cache Storage" button under System > Cache Management.

I'd like to have my extension automatically clear the cache upon being installed. I know how to do the same thing as the button programmatically but I'd prefer not to, because this deletes the entire Magento cache folder and impacts negatively on performance.

Might anyone know how to write code that will clear the caching of my table's schema and do so as specifically as possible - leaving unrelated cached data unharmed?

Update: I've found the file containing my table's schema cache here: /var/cache/mage-f/mage---d07_DB_PDO_MYSQL_DDL_<table_name>_1d . Now how do I target it in code? :)

like image 720
urig Avatar asked May 23 '11 07:05

urig


People also ask

How do I disable Magento cache?

In your Magento backend, go to System > Tools > Cache Management. Check the box on which cache type you want to enable/disable. Then on the top left corner, select the appropriate action (Enable/Disable) and click the Submit button.

What does Flush Magento cache do?

"Flush Magento Cache" removes only those entries that Magento reliably tracks as its own. "Flush Cache Storage" clears everything but might affect other applications if they're using it. Normally the location is var/cache/ in Magento's folder so is not shared after all. It is safe to use either button.

What is the difference between a cache clean and cache flush?

Cache clean does not delete the items which are stored in the cache without proper tags. flush the cache if the cache clean does not reflect the changes at the frontend. Flush cache rubs out every item from the same cache storage.


1 Answers

This is what I've been able to come up with:

$app = Mage::app();
if ($app != null)
{
    $cache = $app->getCache();
    if ($cache != null)
    {
        $cache->clean('matchingTag', array('DB_PDO_MYSQL_DDL'));
    }
}

This will delete only the cache entries and metadata files that hold information about DB schemas.

Note that it will delete these entries for all tables. There's no simple way to clear a specific table's cached schema and leave the rest untouched.

like image 95
urig Avatar answered Nov 03 '22 00:11

urig