【发布时间】:2014-07-17 11:18:57
【问题描述】:
我们正在使用 Magento EE 1.9。
为了加快客户端网站的速度,我们正在尝试微调缓存。
如你所知 Magento 自带了不同的缓存技术。
在 Magento EE 中,我们可以使用全页缓存以及名为“打孔”的技术。 据我了解,这个缓存使用了一些容器来确定 如果应该从缓存中检索动态块 => applyWithoutApp($content) 或者如果应该使用 $this->_renderBlock() => applyWithApp($content) 实例化和渲染动态块
为了做到这一点,您必须在 cache.xml 中声明您想要“打孔”的块,其中包括其适当的容器类扩展 Enterprise_PageCache_Model_Container_Abstract 在这个容器类中,您必须实现不同的功能,例如 _getIdentifier()、_getCacheId()、_renderBlock 如您所见,Contanier 拥有自己的缓存 ID。
这里解释
http://www.magentocommerce.com/wiki/5_-_modules_and_development/block_cache_and_html_ouput 要缓存一个块,您必须通过定义 cache_lifetime,cache_tags,cache_key 直接在 bloc 的构造函数中添加数据
class {NS}_{Module}_Block_{View} extends Mage_Core_Block_Template {
protected function _construct()
{
$this->addData(array(
'cache_lifetime' => 120,
'cache_tags' => array(Mage_Catalog_Model_Product::CACHE_TAG . "_" . $this->getProduct()->getId()),
'cache_key' => $this->getProduct()->getId(),
));
}
}
使用后续帖子进行编辑 http://magebase.com/magento-tutorials/adding-cache-support-to-magento-blocks/
我知道静态的“cache_key”是不够的。 对于这些 cas,我们应该使用 getCacheKeyInfo 方法:
public function getCacheKeyInfo()
{
return array(
'EXAMPLE_BLOCK',
Mage::app()->getStore()->getId(),
(int)Mage::app()->getStore()->isCurrentlySecure(),
Mage::getDesign()->getPackageName(),
Mage::getDesign()->getTheme('template')
);
}
所有这些我回到我的问题: 据我了解,FPC + 打孔似乎是“缓存”的更完整解决方案。 但是全页缓存(带打孔)和“经典”块缓存有什么区别?
-> 由于我们使用的是 Magento EE 1.9,我们应该只使用 FPC + 打孔吗?
(因为在某种程度上FPC+打孔已经是缓存块的一种方式了?)
- 这是否意味着“经典”块缓存已经过时或仅适用于 magento 社区版的用户?
-> 还是应该同时使用(FPC + 打孔和经典块缓存)?
- 在这种情况下,当块拥有自己的缓存键(或 getCacheKeyInfo())时,为容器设置缓存 id 有什么好处?
- 在这种情况下,这些缓存方法中的哪一种是主要的?
提前感谢您的所有回答!
【问题讨论】:
标签: php magento caching hole-punching magento-fpc