Skip to content

Instantly share code, notes, and snippets.

@ivanweiler
Last active August 29, 2015 14:05
Show Gist options
  • Save ivanweiler/11af2f86212457f1a6d0 to your computer and use it in GitHub Desktop.
Save ivanweiler/11af2f86212457f1a6d0 to your computer and use it in GitHub Desktop.
Magento block cache examples
<?php
class Inchoo_Edu_Block_Template extends Mage_Core_Block_Template
{
/*
* Block caching
*
*/
protected function _construct()
{
parent::_construct();
$this->addData(array(
'cache_lifetime' => 48*60*60,
'cache_tags' => array(
Mage_Catalog_Model_Product::CACHE_TAG
)
));
}
public function getCacheKeyInfo()
{
return array_merge(parent::getCacheKeyInfo(), array(
(int)Mage::app()->getStore()->isCurrentlySecure(),
(int)$this->helper('customer')->isLoggedIn()
));
/*
return array(
'CUSTOM_PRODUCT_LIST',
(int)Mage::app()->getStore()->isCurrentlySecure(),
Mage::app()->getStore()->getId(),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
Mage::getDesign()->getPackageName(),
Mage::getDesign()->getTheme('template'),
'template' => $this->getTemplate(),
'name' => $this->getNameInLayout(),
Mage::registry('product')->getId(),
);
*/
}
}
<?php
class Inchoo_Edu_Block_Template extends Mage_Core_Block_Template
{
/*
* Block caching
*
*/
protected function _construct()
{
parent::_construct();
//yes, this enables cache :)
$this->setCacheLifetime(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment