本文整理汇总了PHP中Mage_Core_Block_Abstract::setCacheLifetime方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Block_Abstract::setCacheLifetime方法的具体用法?PHP Mage_Core_Block_Abstract::setCacheLifetime怎么用?PHP Mage_Core_Block_Abstract::setCacheLifetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Block_Abstract
的用法示例。
在下文中一共展示了Mage_Core_Block_Abstract::setCacheLifetime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyCacheSettings
/**
* Apply cache settings to block
* @param Mage_Core_Block_Abstract $block
*/
function applyCacheSettings(&$block)
{
$store = Mage::app()->getStore();
$filterUrl = $this->getFilterUrl();
if (!Mage::getStoreConfigFlag(self::CONFIG_SECTION . '/general/cache_when_url_param') && false !== strpos($filterUrl, '?')) {
// Caching of page with url param disabled in config, and this page has them.
return;
}
if (!Mage::getStoreConfigFlag(self::CONFIG_SECTION . '/general/cache_when_customer_logged_in') && Mage::getSingleton('customer/session')->isLoggedIn()) {
// Caching when customer logged in disabled in config, and customer is logged in.
return;
}
$blockGroup = false;
/** @noinspection PhpUndefinedClassInspection */
if ($block instanceof Mage_Catalog_Block_Category_View || $block instanceof JoomlArt_JmProducts_Block_List) {
$blockGroup = self::BLOCK_GROUP_CATEGORY;
} elseif ($block instanceof Mage_Catalog_Block_Product_View) {
$blockGroup = self::BLOCK_GROUP_PRODUCT;
} elseif ($block instanceof Mage_Catalog_Block_Layer_View || $block instanceof Emico_Tweakwise_Block_Catalog_Layer_View || $block instanceof Mana_Filters_Block_View) {
$blockGroup = self::BLOCK_GROUP_LAYERED_NAV;
} elseif ($block instanceof Mage_Cms_Block_Page) {
$blockGroup = self::BLOCK_GROUP_CMS_PAGE;
} elseif ($block instanceof Mage_Cms_Block_Block || $block instanceof Mage_Cms_Block_Widget_Block) {
$blockGroup = self::BLOCK_GROUP_CMS_BLOCK;
}
for ($c = 1; $c <= 5; $c++) {
$matches = trim(Mage::getStoreConfig(self::CONFIG_SECTION . '/custom_' . $c . '/instanceof'));
if ($matches) {
$matches = explode("\n", $matches);
foreach ($matches as $match) {
$match = trim($match);
if (empty($match)) {
continue;
}
if (false !== strpos($match, '/')) {
$match = Mage::getConfig()->getBlockClassName($match);
}
if (!empty($match) && $block instanceof $match) {
$blockGroup = constant('self::BLOCK_GROUP_CUSTOM_' . $c);
}
}
}
}
if (false === $blockGroup) {
// It is a block group we don't change caching for.
return;
}
$cacheLifeTime = null;
if (Mage::getStoreConfigFlag(self::CONFIG_SECTION . '/' . $blockGroup . '/enable_cache')) {
$cacheLifeTime = intval(Mage::getStoreConfig(self::CONFIG_SECTION . '/' . $blockGroup . '/lifetime'));
}
/** @noinspection PhpUndefinedMethodInspection */
$block->setCacheLifetime($cacheLifeTime);
if ($cacheLifeTime) {
$currentCategory = null;
$currentProduct = null;
$cacheKey = self::CACHEKEY_START;
$cacheKeyData = '';
$cacheTags = array();
switch ($blockGroup) {
case self::BLOCK_GROUP_CATEGORY:
$cacheKey .= self::CACHEKEY_GROUP_CATEGORY;
$currentCategory = Mage::registry('current_category');
// Add sorting & paging to cache key
$catalogSession = Mage::getSingleton('catalog/session');
if ($catalogSession) {
/** @noinspection PhpUndefinedMethodInspection */
$cacheKeyData .= '|so' . strval($catalogSession->getSortOrder());
/** @noinspection PhpUndefinedMethodInspection */
$cacheKeyData .= '|sd' . strval($catalogSession->getSortDirection());
/** @noinspection PhpUndefinedMethodInspection */
$cacheKeyData .= '|dm' . strval($catalogSession->getDisplayMode());
/** @noinspection PhpUndefinedMethodInspection */
$cacheKeyData .= '|lp' . strval($catalogSession->getLimitPage());
}
break;
case self::BLOCK_GROUP_PRODUCT:
$cacheKey .= self::CACHEKEY_GROUP_PRODUCT;
$currentCategory = Mage::registry('current_category');
$currentProduct = Mage::registry('current_product');
break;
case self::BLOCK_GROUP_LAYERED_NAV:
$cacheKey .= self::CACHEKEY_GROUP_LAYERED_NAV;
$currentCategory = Mage::registry('current_category');
break;
case self::BLOCK_GROUP_CMS_PAGE:
$cacheKey .= self::CACHEKEY_GROUP_CMS_PAGE;
$cmsPage = Mage::getSingleton('cms/page');
if ($cmsPage instanceof Mage_Cms_Model_Page) {
$cacheTags[] = Mage_Cms_Model_Page::CACHE_TAG . '_' . $cmsPage->getId();
$cacheKey .= 'P' . $cmsPage->getId() . '_';
}
break;
case self::BLOCK_GROUP_CMS_BLOCK:
/** @noinspection PhpUndefinedMethodInspection */
$cacheKey .= self::CACHEKEY_GROUP_CMS_BLOCK;
//.........这里部分代码省略.........
示例2: testGetCacheLifetime
public function testGetCacheLifetime()
{
$this->assertNull($this->_block->getCacheLifetime());
$this->_block->setCacheLifetime(1800);
$this->assertEquals(1800, $this->_block->getCacheLifetime());
}