Bitrix Site Manager

CBitrixComponent::SetTemplateCachedData

void 
SetTemplateCachedData(
 mixed templateCachedData
);

The SetTemplateCachedData method is called if the proprietary component caching mechanism is not used, but calls to CBitrixComponent::IncludeComponentTemplate is cached. This method returns data that were saved in cache.

Example


// Check and initialize input parameters
if ($arParams["ID"] <= 0)
   $arParams["ID"] = 10;

$arParams["CACHE_TIME"] = IntVal($arParams["CACHE_TIME"]);
$CACHE_ID = SITE_ID."|".$APPLICATION->GetCurPage()."|";
// cache depends only on the prepared parameters without "~"
foreach ($this->arParams as $k => $v)
    if (strncmp("~", $k, 1))
        $CACHE_ID .= ",".$k."=".$v;
$CACHE_ID .= "|".$USER->GetGroups();

$cache = new CPageCache;
if ($cache->StartDataCache($arParams["CACHE_TIME"], $CACHE_ID, "/".SITE_ID.$this->GetRelativePath()))
{
    // Query data and form the $arResult array
    $arResult = array("a" => 1, "b" => 2);

    // Include the component template
    $this->IncludeComponentTemplate();

    $templateCachedData = $this->SetTemplateCachedData();

    $cache->EndDataCache(
        array(
            "arResult" => $arResult,
            "templateCachedData" => $templateCachedData
        )
    );
}
else
{
    extract($cache->GetVars());
    $this->SetTemplateCachedData($templateCachedData);
}

See Also

  • Component caching
  • CBitrixComponent::GetTemplateCachedData