int cacheTime [,
 string additionalCacheID [,
 string cachePath]]]

The method updates support of internal component caching. Non-static method.

If cache is valid, the method displays its content, fills out $arResult and returns False. If the cache is invalid, the method returns True, caching finishes and cache is saved immediately after component template is connected when calling methods CBitrixComponent::IncludeComponentTemplate or CBitrixComponent::ShowComponentTemplate.


cacheTime Caching time in seconds. If this parameter is False, caching time is taken from the parameter $arParams["CACHE_TIME"]. Optional.
additionalCacheID Cache depends on the current site (SITE_ID), component name, template name, input parameters $arParams. If cache must depend on specific additional parameters, they must be passed in this parameter as a string. Parameter default value is False, i. e. cache depends only on the current sites SITE_ID, component name, template name and the input parameters. $arParams. Optional.
cachePath Cache file path relative to cache folder. By default equals to "/".SITE_ID.<component path relative to bitrix/components>. Optional.

Returned value

Returns True in case if cache is invalid or False otherwise.


// Verification and initialization of input parameters
if ($arParams["ID"] <= 0)
    $arParams["ID"] = 10;

// If there are no valid cache (i. e. the data must be requested
// and cache validated)
if ($this->StartResultCache())
    // Data request and filling out of $arResult
    $arResult = array(
        "ID" => rand(1, 100)

    for ($i = 0; $i < 5; $i++)
        $arResult["FIELDS"][] = rand(1, 100);

    // If a condition is met,
    // data caching is not required
    if ($arParams["ID"] < 10)

    // Connect the display template

// Specify page header via delayed 
// function

// cache must depend on user groups that include the visitor
if ($this->StartResultCache(false, $USER->GetGroups()))
   // Valid cache is unavailable. Sel ect data fr om
   // database in $arResult

See Also

  • CBitrixComponent::AbortResultCache
  • CBitrixComponent::ClearResultCache

  • © «Bitrix24», 2001-2023