Views: 8669
Last Modified: 18.09.2014
When performing instructions of this lesson, it is assumed that you have tagged caching activated.
Solution 1
Add the following code in the component body:
if ($this->StartResultCache(......))
{
if (defined('BX_COMP_MANAGED_CACHE') && is_object($GLOBALS['CACHE_MANAGER']))
{
$GLOBALS['CACHE_MANAGER']->RegisterTag('my_custom_tag');
}
// do something
$this->IncludeComponentTemplate();
}
else
{
$this->AbortResultCache();
}
Solution 2
Add the following code to the component template (в result_modifier.php):
<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
if (defined('BX_COMP_MANAGED_CACHE') && is_object($GLOBALS['CACHE_MANAGER']))
{
$cp =& $this->__component;
if (strlen($cp->__cachePath))
{
$GLOBALS['CACHE_MANAGER']->RegisterTag('my_custom_tag');
}
}
?>
To reset all of the caches marked with your tag, execute the following code:
if (defined('BX_COMP_MANAGED_CACHE') && is_object($GLOBALS['CACHE_MANAGER']))
$GLOBALS['CACHE_MANAGER']->ClearByTag('my_custom_tag');
Note: The same cache can be marked with several tags. For example, if you mark the cache of the component bitrix:news.list with your tag, the cache will have two tags: the standard "iblock_id_XX" and your "my_custom_tag". Accordingly, the cache will be reset both in case of adding/changing an element in the infoblock XX (standard functionality) and in case of resetting cache manually through ClearByTag('my_custom_tag')
.