我注意到我的主页需要很长时间才能加载 - 根据 site24x7.com 事实上超过 6 秒,所以我一直在关闭元素以尝试确定原因是什么,这取决于我制作的 2 个产品集合文件展示新产品和畅销产品。
当我从主页中删除这些内容后,页面加载时间不到 0.5 秒。
那么,有人可以帮助优化和缓存产品集合吗?我在服务器上安装并运行了 APC,但我不确定它是否缓存位于 app/design/frontend/default/MY_THEME/catalog/product/newproducts.phtml 中的文件
所以,我的最畅销系列(实际上浏览次数最多)看起来像这样;
<?php $storeId = Mage::app()->getStore()->getId(); // return current store id ?>
<?php $_productCollection= Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addStoreFilter($storeId)
->addViewsCount()
->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->addFieldToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$_productCollection->getSelect()->limit(8)
?>
我该如何进一步优化这个?
Try
$storeId = Mage::app()->getStore()->getId();
$cache = Mage::getSingleton('core/cache');
$key = 'homepage-most-view-' . $storeId;
if(! $data = $cache->load($key)){
$_productCollection= Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addStoreFilter($storeId)
->addViewsCount()
->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->addFieldToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
$_productCollection->getSelect()->limit(8)
// get the element you need from $_productCollection and store in $array
$data = serialize($array);
$cache->save(urlencode($data), $key, array("homepage_cache"), 60*60*24);
}
else{
$data = unserialize(urldecode($data));
}
See
- http://www.nicksays.co.uk/developers-guide-magento-cache/ http://www.nicksays.co.uk/developers-guide-magento-cache/
-
http://inhoo.net/ecommerce/magento/magento-block-caching/ http://inchoo.net/ecommerce/magento/magento-block-caching/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)