Magento Enterprise - 无效缓存

时间:2012-09-27 01:35:53

标签: magento

只是一个简单的问题:

无效缓存是否表示缓存未运行?

1 个答案:

答案 0 :(得分:4)

不,只是意味着它需要刷新。

在Magento中,无论何时对产品,静态块等进行更改,它都会识别出数据库中的数据不再与缓存中的数据相同。不幸的是,Magento没有意识到什么缓存数据是不同的,只是某些东西是不同的。

您需要进入系统>缓存管理并刷新无效的缓存类型。

如果您愿意,可以将其设置为自动刷新。

创建一个模块(或使用现有模块),您可以使用该模块设置cron作业以刷新缓存。创建一个文件:{namespace} / {modulename} /Model/Observer.php

在该文件中:

<?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());
    }
  }

}

在你的模块的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>

现在,只要在服务器上正确配置了cron,缓存就会自动更新,就像cron运行一样。

相关问题