Question

I am getting the following error message a few times a day, and my knowledge of the inner workings of Magento CE 1.9.0.1 is thin enough that I don't know if this is normal, advisory behavior from Magento, or if it is telling me I have a bad problem.

Here is the message:

One or more of the Cache Types are invalidated: Blocks HTML output. Click here to go to Cache Management and refresh cache types.

Refreshing that particular cache makes the problem go away for a couple hours or so.

I am not currently editing layouts, products, etc., nothing at all.

What is wrong and how can I correct it?

Was it helpful?

Solution

First it is important to understand that this is not an error, it is merely a notification.

There can be myriad of reasons a block cache is invalidate from updates to products, catalog price rule changes, and 3rd party extensions. Also running of cronjobs can cause block caches to become invalidated as well.

There are some community extensions available (listed below) that will refresh your blocks as the become invalidated.

https://github.com/tomasinchoo/Inchoo_InvalidatedBlockCacheFix

https://github.com/mklooss/Loewenstark_InvalidCache

OTHER TIPS

This IS an error.

There is a CRON job problem (post 1.9.?) that runs and invalidates the HTML Cache, which produces problems (e.g. in my case, failed to carry over price discount to the Basket - so a customer would be charged wrong amount).

We shouldn't need to run an extension to fix a problem that has been introduced!

This is standard Magento operation from 1.6.x.x and forward. Something is always causing a random html block cache invalidation.

I just set up an observer that fires off on a periodic cron job, set whatever interval seems appropriate.

Observer.php

<?php

/************************
 * Find invalidated cache types and refresh
 *
 * Set Cron Time for refresh in config.xml
 *
 */

class Fiasco_Rcache_Model_Observer {

    public function refreshCache() {

        try {

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

            foreach($types as $type) {

                Mage::app()->getCacheInstance()->cleanType($type->getId());

            }

            Mage::log('Invalid Cache Types Refreshed');

        } catch (Exception $e) {

            Mage::logException($e);

        }
    }
}

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Fiasco_Rcache>
            <version>0.5.0</version>
        </Fiasco_Rcache>
    </modules>
    <global>
        <models>
            <refresh_cache>
                <class>Fiasco_Rcache_Model</class>
            </refresh_cache>
        </models>
    </global>
    <crontab>
        <jobs>
            <refresh_cache>
                <!-- Min Hour Day Month DoW -->
                <schedule><cron_expr>0 */3 * * *</cron_expr></schedule>
                <run><model>refresh_cache/observer::refreshCache</model></run>
            </refresh_cache>
        </jobs>
    </crontab>
</config>

This invalidated cache indicator is probably related to the dailyCatalogUpdate cron. It is responsible for applying/refreshing catalog rules.

Once a day, it calls Mage::getSingleton('catalogrule/rule')->applyAll();.

Inside the code of this method, there is a call to $this->_invalidateCache(), which in turn calls $this->_app->getCacheInstance()->invalidateType() on the block_html cache.

The issue is that it invalidates the cache without doing any checks to determine if it might actually still be valid. To me, this is better than not invalidating the cache, because then you can at least know that it could be invalid, and use something like what Fiasco Labs suggested to flush the (potentially) invalid cached data.

It then becomes a decision as to whether you want to error on the side of:

A) Showing customers the wrong price, but keeping the cache, and thus having less server load

or

B) Showing the correct price, but having more cache misses, and therefore higher server load.

There are two hard things in computer science: naming things and cache invalidation.

see here the solution: https://magento.stackexchange.com/a/72687

Basically change the function dailyCatalogUpdate from app/code/local/Mage/CatalogRule/Model/Observer.php to

        $collection = Mage::getResourceModel('catalogrule/rule_collection')
        ->addFieldToFilter('is_active', array('neq' => 0));
    if ($collection->getSize() == 0) {
        return $this;
    }
    parent::dailyCatalogUpdate($observer);
    $types = Mage::getConfig()->getNode('global/catalogrule/related_cache_types')->asArray();
    foreach (array_keys($types) as $type) {
        Mage::app()->getCacheInstance()->cleanType($type);
    }
    return $this;
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top