Skip to content

Instantly share code, notes, and snippets.

@ivanweiler
Last active August 29, 2015 14:05
Show Gist options
  • Save ivanweiler/694c0aaf23deab2a38a9 to your computer and use it in GitHub Desktop.
Save ivanweiler/694c0aaf23deab2a38a9 to your computer and use it in GitHub Desktop.
<?php
class Inchoo_Edu_Model_Resource_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
/*
* Collection that always caches all its queries
*
*/
protected function _construct()
{
$this->_init('inchoo_edu/dummy');
$this->initCache(
Mage::app()->getCache(),
'dummy_collection',
array()
);
}
}
<?php
class Inchoo_Edu_Model_Example
{
public function getCachedCollection()
{
//Mage_Core_Model_Resource_Db_Collection_Abstract
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(array('name', 'image', 'url'))
->addPriceData()
->addUrlRewrite();
$collection->initCache(
Mage::app()->getCache(),
'INCHOO_EDU_PRODUCTS',
array(Mage_Catalog_Model_Product::CACHE_TAG)
);
return $collection;
/*
$websiteCollection = Mage::getModel('core/website')->getCollection()
->initCache(
Mage::app()->getCache(),
'app',
array(Mage_Core_Model_Website::CACHE_TAG)
)
->setLoadDefault(true);
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment