在Block类的_construct(不是构造方法)方法中加入以下代码:
Php代码
public function _construct()
{
$this->addData(
array(
'cache_lifetime' => 3600,
'cache_tags' => array(Mage_Catalog_Model_Product::CACHE_TAG),
'cache_key' => 'productfaq_'.Mage::registry('product')->getId().'_'.Mage::app()->getStore()->getId()
. '_' . Mage::getDesign()->getPackageName()
. '_' . Mage::getDesign()->getTheme('template')
. '_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
)
);
parent::_construct();
}
cache_key必须唯一。
在获得数据的方法中加入:
Php代码
$faq_data = @unserialize( Mage::app()->loadCache($this->getCacheKey()) );
//从数据库取出数据并存入到faq_data 中
if (!$faq_data) {
$faq_data = array();
...
$faq_data[]=array('customer_id' => $customerId,
'name' => $sName,
'avatar' => $sAvatar,
'question' => $sQuestion,
'answer' => $sAnswer,
);
}
Mage::app()->saveCache(serialize($faq_data), $this->getCacheKey(), $this->getCacheTags(),$this->getCacheLifetime());
分享到:
相关推荐
magento中block应用 magento中block应用 magento中block应用
Block items can include any content that Magento CMS can involve Powerful block view scheduler Per-category and per-store view aheadWorks Market Segmentation Suite extension integration Enabling/...
一个简单的模块,将缓存信息添加到Mage_Catalog_Block_Product_List从而在产品列表上启用块缓存。 该模块是为上的教程创建的。 你为什么要安装这个? 简短答案: 更好的性能。 中等答案: 您可能熟悉Magento的块...
magento footer no cache,不缓存页面底部footer部分
Magento全页缓存插件,适用于1.6-1.8社区版
magento 加速插件 full page cache 效果很好很强大 速度非常快 花了我几十美金
magento1.9 邮件发送失败解决方法,附带视频教程和图片,文字和修改好的文件,只测试过1.9版本. 其他版本没遇到这个问题
magento 常用的方法 与 总结, 对于起步学习magento 的非常有帮助
magento的SMTP插件magento的SMTP插件magento的SMTP插件
magento csv多图批量导入 解决方法
magento数据结构分析 magento数据字典
magento全页缓存
In Magento 2, the Full Page Cache (FPC) can be handled by Varnish to give your store a performance boost. There are also external services that you can use as a cache. Chapter 4, Creating Catalogs ...
使用Docker-Compose工具在多容器架构上设置Magento 2和Varnish缓存 该存储库对应于博客提到的架构设置。 Docker-撰写工具 如Docker文档中所述,Compose是用于定义和运行多容器Docker应用程序的工具。 通过Compose,...
magik shoes magento 模板, magento 1.7 模板
MB_属性 在 Magento 1.x 中为购物车价格规则/优惠券添加属性的简单模块。 请参阅此处的完整讨论:magento.stackexchange.com/questions/67949/add-attribute-to-shopping-cart-price-rule-coupon/
将自定义属性添加到Magento类别 用于将自定义属性添加到Magento类别的模块。 我已经设置了位于app / code / local / Samuidavid / CustCatAttr / sql / custcatattr_setup中的安装脚本,以将新的图像输入字段添加到...
深入理解Magento 由精东博客下载下来制作成pdf
Magento插件开发手册 Magento Extension Developers Guide
NULL 博文链接:https://hudeyong926.iteye.com/blog/1416591