9

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?

  • I get this every day when I wake up and sign in on Magento v1.9.2.2 - One or more of the Cache Types are invalidated: Blocks HTML output. Click here to go to Cache Management and refresh cache types. I never used to get this on earlier versions unless I was actually doing something. Is this some kind of bug? – Neal Hart Jan 16 '16 at 19:26
6

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

| improve this answer | |
2

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!

| improve this answer | |
  • I am getting the exact same behaviour on CE 1.9.2.2, every morning Blocks HTML output needs to be refreshed, and thought about a cron job issue. @Brian could you give further details on that cron task? – Marc Dec 16 '15 at 8:29
  • I think that you are thinking backwards though: It was not that the "price didn't carry over to the basket," but rather that the price on the page was added to the cache before the refresh ran, and therefore the cache was wrong, while the correct price shown in the cart. To the buyer though, they probably think that whichever price is lower is the "correct" one. – Eric Seastrand Feb 4 '16 at 19:41
  • @Brian, Could you give further details on the cron task that was invalidating your blocks? – Haim May 12 '16 at 3:16
0

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>
| improve this answer | |
0

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.

| improve this answer | |
0

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;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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