Hello, tell me, please, how from init.php or from an event handler, reset the component template cache using the Bitrix API?

    2 answers 2

    New API

    $staticHtmlCache = \Bitrix\Main\Data\StaticHtmlCache::getInstance(); $staticHtmlCache->deleteAll(); 

    and a description of some of the details here.

    "Old" API

    Deletes all (or only obsolete) cache files at the specified path.

     BXClearCache() 

    Read more here.

    Method to support internal component caching. It is used if under certain conditions it is required to clear the component cache

     ClearResultCache() 

    Read more here.

    • It seems to me that this does not fit, since this function resets the entire html cache, and I need a specific component, I tried to clearResultCache, but I have errors there when changing the information block element. - Sempom

    I found a solution) and for some reason I did not find this function in the documentation ( enter image description here

     <? AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", Array("MyClass4", "OnBeforeIBlockElementUpdateHandler")); class MyClass4 { function OnBeforeIBlockElementUpdateHandler(&$arFields) { if ($arFields['IBLOCK_ID'] == 3) { CBitrixComponent::clearComponentCache('simplecomp:simplecomp.exam4'); } } } ?> 
    • Write the text of the program as text - tutankhamun
    • To you with comments? - Sempom
    • I don't care at all, I don’t use Bitrix :) It’s just desirable that there is a text in which your answer can be found and it can be useful to someone else. And you may have a plus sign ;) - tutankhamun
    • And by the way, the remark is off topic. Try not to use tags <? (in favor of <?php ) This does not apply to <?= - personally, I am in favor of such use. - tutankhamun
    • these are the requirements of Bitrix - Sempom