嘿 Magento 专业人士,
我使用 Magento 块缓存机制在产品页面上获得更好的性能。它在 Magento CE 1.6.2 上运行良好,但现在我升级到 CE 1.9.0.1 并且块缓存不适用于 Magento 新表单键。
产品页面仍在缓存中,但它们自然会被缓存,包括表单操作中的新表单键。当另一个用户尝试将产品添加到购物车时,它将不起作用,因为其他用户的表单键已被缓存。因此,没有添加任何产品,购物车保持为空。
有没有办法将表单键注入缓存代码或另一种缓存产品页面的方法?
我扩展的 Mage_Catalog_Block_Product_View 中的缓存方法如下所示
protected function _construct()
{
$this->addData(array(
'cache_tags' => array(Mage_Catalog_Model_Product::CACHE_TAG . "_" . $this->getProduct()->getId()),
));
}
public function getCacheKey()
{
if (!$this->hasData('cache_key')) {
//$cacheKey = LAYOUTNAME_STORE+ID_PRODUCT+ID
$cacheKey = $this->getNameInLayout().'_STORE'.Mage::app()->getStore()->getId().'_PRODUCT'.$this->getProduct()->getId();
$this->setCacheKey($cacheKey);
}
return $this->getData('cache_key');
}
public function getCacheLifetime()
{
if($this->getNameInLayout()!='product.info') return null;
if(!$this->cacheEnabled()) return null;
return 9999999999;
}
public static function cacheEnabled() {
return true;
}