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? :)
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.
"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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With