Last active
August 29, 2015 14:05
-
-
Save ivanweiler/11af2f86212457f1a6d0 to your computer and use it in GitHub Desktop.
Magento block cache examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(), | |
); | |
*/ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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