Documentation

EndDataCache

CPHPCache::EndDataCache(
 mixed vars = false
)

The method outputs the buffered HTML and saves it to cache file on drive together with the specified array of variables into the cache file. non-static method.

Analog method is available in the new core: Bitrix\Main\Data\Cache::endDataCache .

Parameters

ParameterDescription
vars Array of variables which values must be recorded into the cache file. Array type can be as follows:
array(
 "VARIABLE NAME 1" => "VARIABLE VALUE 1", 
 "VARIABLE NAME 2" => "VARIABLE VALUE 2", 
 ...)
Optional. An array of variables specified in the function CPHPCache::StartDataCache is used by default.

See Also

  • CPHPCache::StartDataCache

    Examples of use

    <?
    // create an object
    $obCache = new CPHPCache; 
    
    // caching time - 30 minutes 
    $life_time = 30*60; 
    
    // form the cache ID according to all parameters 
    // which may affect the resulting HTML
    $cache_id = $ELEMENT_ID.$SECTION_ID.$USER->GetUserGroupString(); 
    
    // if the cache exists and is not expired then
    if($obCache->InitCache($life_time, $cache_id, "/")) :
        // obtain cached variables
        $vars = $obCache->GetVars();
        $SECTION_TITLE = $vars["SECTION_TITLE"];
    else :
        // otherwise call database
        $arSection = GetIBlockSection($SECTION_ID);
        $SECTION_TITLE = $arSection["NAME"];
    endif;
    
    // add a menu item to the navigation chain
    $APPLICATION->AddChainItem($SECTION_TITLE, $SECTION_URL."SECTION_ID=".$SECTION_ID);
    
    // start buffered output
    if($obCache->StartDataCache()):
    
        // obtain the information block element parameters from the database
        if($arIBlockElement = GetIBlockElement($ELEMENT_ID, $IBLOCK_TYPE)):
            echo "<pre>"; print_r($arIBlockElement); echo "</pre>";
        endif;
    
        // write the preliminary buffered output to the cache file
        // together with an additional variable
        $obCache->EndDataCache(array(
            "SECTION_TITLE"    => $SECTION_TITLE
            )); 
    endif;
    ?>


  • © «Bitrix24», 2001-2024
    Up