什么是“无效"?缓存在Magento中意味着什么? [英] What does "invalidated" cache mean in Magento?

查看:85
本文介绍了什么是“无效"?缓存在Magento中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Magento管理员的缓存管理"下,当显示缓存无效时,这是什么意思? Magento如何知道缓存无效?特别是,我想知道有关HTML Block缓存的信息.什么条件会导致此缓存显示为无效?

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?

推荐答案

在Magento中,每当您对产品,静态块等进行更改时,它都会识别出数据库中的数据不再与数据库中的数据相同.缓存.不幸的是,Magento并没有意识到什么缓存数据是不同的,只是某些事情是不同的.

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.

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

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

在该文件内:

<?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中:

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>

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

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

这篇关于什么是“无效"?缓存在Magento中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆