What does “invalidated” cache mean in Magento?

后端 未结 3 495
北恋
北恋 2021-01-30 23:38

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 wonderin

3条回答
  •  天命终不由人
    2021-01-31 00:09

    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:

    __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:

    
      ...
      
        
          <{modulename}_refresh_cache>
            * * * * *
            {modulename}/observer::refreshCache
          
        
      
      ...
    
    

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

提交回复
热议问题