GetTemplateCachedData
mixed GetTemplateCachedData();
The method GetTemplateCachedData is called when the component in-built caching is not used and calling IncludeComponentTemplate is cached. This method returns data that is required to be saved in and then restored from the cache - to be returned to the template by the method SetTemplateCachedData. Non-static method.
Example
// Verification and initialization of 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 formatted 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); // Connect the component template $this->IncludeComponentTemplate(); $templateCachedData = $this->GetTemplateCachedData(); $cache->EndDataCache( array( "arResult" => $arResult, "templateCachedData" => $templateCachedData ) ); } else { extract($cache->GetVars()); $this->SetTemplateCachedData($templateCachedData); }
See Also
© «Bitrix24», 2001-2024