'Blocks HTML' Cache Types are invalidated

升級magento到1.5之後,後臺Cache Storage Management那裏好像出現了一點小問題,基本上每次將Blocks HTML output改爲enabled之後,第二天又會是invalidated(我這裏因爲cron每天都會執行catalogrule),或者每次在後臺任意點開某個product,然後再save,Blocks HTML output也會從enabled變爲invalidated,google了一下,很多人好像都遇到了這個問題,類似於One or more of the Cache Types are invalidated: Blocks HTML output. Click here to go to Cache Management and refresh cache types.這樣的提示。

通過看源碼之後發現,這個bug似乎又不像是個bug,爲什麼呢?看catalogrule的config.xml,裏面有段
        <catalogrule>
            <related_cache_types>
                <block_html/>
            </related_cache_types>
        </catalogrule>

我們發現,和catalogrule關聯的cache塊是block_html,我說的cache塊是指進後臺Cache Storage Management,Associated Tags對應的值,只不過後臺是大寫的。

當我們進入後臺product編輯頁,即便什麼也不做,點save,經過層層觸發,會進入CatalogRule/Model/Rule.php,看function applyAllRulesToProduct,有$this->_invalidateCache()這麼一句,再進入function _invalidateCache,code如下:
    protected function _invalidateCache()
    {
        $types = Mage::getConfig()->getNode(self::XML_NODE_RELATED_CACHE);
        if ($types) {
            $types = $types->asArray();
            Mage::app()->getCacheInstance()->invalidateType(array_keys($types));
        }
        return $this;
    }

$types = Mage::getConfig()->getNode(self::XML_NODE_RELATED_CACHE)這一句替換完宏就是
$types = Mage::getConfig()->getNode('global/catalogrule/related_cache_types'),看最上面的config.xml,$types最終得到的值是block_html,所以下面的invalidateType就將block_html設爲了invalidated。

這裏我也很迷惑,不知道magento的用意是什麼?貌似1.4版本不會出現這個問題。
相關解決方法及討論http://www.magentocommerce.com/boards/viewthread/219407/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章