Documentation

SetTemplateCachedData

void 
SetTemplateCachedData(
 mixed templateCachedData
);

The method SetTemplateCachedData is called when the component in-built caching is not used but calling CBitrixComponent::IncludeComponentTemplate is cached. This method returns data to the template which should have been saved in cache. Non-static method.

Example

// Verifying and initializing 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 parameters specified without "~"
foreach ($this->arParams as $k => $v)
    if (strncmp("~", $k, 1))
        $CACHE_ID .= ",".$k."=".$v;
$CACHE_ID .= "|".$USER->GetGroups();

$cache = new CPHPCache;
if ($cache->StartDataCache($arParams["CACHE_TIME"], $CACHE_ID, "/".SITE_ID.$this->GetRelativePath()))
{
    // Data request and $arResult array formatting
    $arResult = array("a" => 1, "b" => 2);

    // Connecting template component
    $this->IncludeComponentTemplate();

    $templateCachedData = $this->GetTemplateCachedData();

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

See Also

  • Component caching
  • CBitrixComponent::GetTemplateCachedData


  • © «Bitrix24», 2001-2022
    Up