Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Last active September 10, 2015 02:55
Show Gist options
  • Select an option

  • Save ryaan-anthony/be418be99089fd5854bf to your computer and use it in GitHub Desktop.

Select an option

Save ryaan-anthony/be418be99089fd5854bf to your computer and use it in GitHub Desktop.
<?php
class My_Foo_Block_Thing extends Mage_Core_Block_Template
{
protected $_cacheKey = "your-cache-key";
protected function _construct()
{
$this->addData([
'cache_lifetime'=> false,
'cache_tags' => [
Mage_Core_Model_Store::CACHE_TAG,
Mage_Cms_Model_Block::CACHE_TAG
]
]);
parent::_construct();
}
/**
* Get cache key informative items
*
* @return array
*/
public function getCacheKeyInfo()
{
/** @var Mage_Customer_Model_Session $customerSession */
$customerSession = Mage::getSingleton('customer/session');
return [
$this->_cacheKey,
Mage::app()->getStore()->getId(),
(int)Mage::app()->getStore()->isCurrentlySecure(),
Mage::getDesign()->getPackageName(),
Mage::getDesign()->getTheme('template'),
$customerSession->isLoggedIn() ? $customerSession->getCustomerId() : 'guest'
];
}
/**
* Retrieve child block HTML, sorted by default
*
* @param string $name
* @param boolean $useCache
* @return string
*/
public function getChildHtml($name='', $useCache=true, $sorted=true)
{
return parent::getChildHtml($name, $useCache, $sorted);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment