Magento – Refresh specific cache only if invalidated

cachemagento-1.9

Magento ver. 1.9.0.0

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:

Mage::app()->getCacheInstance()->cleanType('block_html');

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

Many thanks

Best Answer

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.