Magento ver.

I keep getting the BLOCK_HTML cache becoming invalid and this is stopping some external blocks of code from displaying until I refresh the cache. I see that I can flush the cache in my code as follows:


I would like to call this only if the cache is invalid, is it possible to check if the cache in invalidated?

Many thanks

2 Answers 2


Mage::app()->getCacheInstance()->getInvalidatedTypes() should return a list of all invalidated types. You could then match block_html against it to ensure that the ID is in the array before clearing it.


I use Bitnami Magento Stack, for me this solution below was the best I have found.

I've tried to create a Mage_Shell_Class php file, but without success (invalid cache array were always empty when it runs, no matter what, and I really don't imagine why).

I've created a php file 'sample.php':


require 'app/Mage.php';

$invalid = Mage::app()->getCacheInstance()->getInvalidatedTypes();

foreach($invalid as $i)

I've placed it on magento root folder, and to start it I use a cronjob that runs under root user.

So, to create the cronjob on the root user:

sudo crontab -u root -e

And this was my command line to run it:

* * * * * . /opt/bitnami/scripts/setenv.sh ; /opt/bitnami/php/bin/php /opt/bitnami/apps/magento/htdocs/sample.php >> /var/log/cron/cron.log 2>&1

Some parts on this line are very particular to my problem:

  1. Since it just refreshes the invalidated caches I've decided to run it every minute.
  2. setenv.sh is a script that helps me to set the environment when dealing with this particular bitnami stack.
  3. To get the output of this script I used this last part ">> /var/log/cron/cron.log 2>&1" to output errors to a directory that I've created (/var/log/cron), and has given the correct permissions on it.

Probably you need to change the cron line command, but I think this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.