Magento how to cache a productCollection

前端 未结 2 591
无人共我
无人共我 2021-02-03 14:44

Ive noticed my home page is taking a long time to load - over 6 seconds infact according site24x7.com, so ive been switching elements off to try and determine what is the cause,

2条回答
  •  被撕碎了的回忆
    2021-02-03 15:35

    If you want to cache $collection, there is already a built-in possibility for collection caching in Magento.

     $_productCollection= Mage::getResourceModel('reports/product_collection');
    
    $cache = Mage::app()->getCache(); //Let's get cache instance
            $cache->setLifetime(86400); //Here we set collection cache lifetime
            $_productCollection->initCache(
                $cache,
                'Bestsellers_', //this is just custom prefix
                array('collections') 
            );
        }
    

    Credit for above code: apiworks.net (http://www.apiworks.net/2015/01/magento-collection-caching.html)

提交回复
热议问题