How to clear Magento caching from its DB schema?

I am developing a Magento extension that injects a new table into a database. Whenever I release a new version of an extension that makes changes to the table layout, I find that users are forced to manually click the Clear Cache button in System> Cache Management.

I want my extension to automatically clear the cache during installation. I know how to do the same thing as a button programmatically, but I would prefer not to, because it deletes the entire Magento cache folder and negatively affects performance.

Maybe someone knows how to write code that will clear the caching of my table schema and do it as specific as possible - leaving the unrelated cached data intact?

Update: here I found a file containing my table schema cache: /var/cache/mage-f/mage---d07_DB_PDO_MYSQL_DDL_<table_name>_1d . Now, how do you target your code? :)

+6
source share
1 answer

Here is what I came 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 cache entries and metadata files containing information about database schemas.

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

+8
source

Source: https://habr.com/ru/post/888797/


All Articles