Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "invalidated" cache mean in Magento?

Tags:

magento

In the Magento admin under Cache Management, what does it mean when it shows a cache as invalidated? How does Magento know a cache is invalidated? In particular, I'm wondering about HTML Block cache. What conditions would cause this cache to show up as invalidated?

like image 459
localfilmmaker Avatar asked Dec 07 '11 22:12

localfilmmaker


1 Answers

In Magento, whenever you make changes to products, static blocks, etc, it recognizes that the data in the database is no longer the same as what it has in the cache. Unfortunately, Magento doesn't realize what cache data is different, just that something is different.

You will need to go into System > Cache Management and refresh the invalidated cache types.

EDIT:

Create a module (or use an existing module) that you can use to set up a cron job for refreshing the cache. Create a file: {namespace}/{modulename}/Model/Observer.php

Inside that file:

<?php
class <namespace>_<modulename>_Model_Observer {

  public function refreshCache() {
    try {
      $allTypes = Mage::app()->useCache();
      foreach($allTypes as $type => $blah) {
        Mage::app()->getCacheInstance()->cleanType($type);
      }
    } catch (Exception $e) {
      // do something
      error_log($e->getMessage());
    }
  }

}

In your module's etc/config.xml:

<config>
  ...
  <crontab>
    <jobs>
      <{modulename}_refresh_cache>
        <schedule><cron_expr>* * * * *</cron_expr></schedule>
        <run><model>{modulename}/observer::refreshCache</model></run>
      </{modulename}_refresh_cache>
    </jobs>
  </crontab>
  ...
</config>

Now as long as cron is configured correctly on your server, the cache will update automatically, as often as cron runs.

like image 103
Magento Guy Avatar answered Sep 21 '22 15:09

Magento Guy