Bitrix Site Manager

CPageCache::StartDataCache

bool
CPageCache::StartDataCache(
 int cache_life_time,
 string cache_id,
 mixed init_dir = false
)

The method StartDataCache starts buffered HTML output, or outputs the cache content if it is not expired yet. If the cache file is expired, the function returns true, or false otherwise. 

Parameters

ParameterDescription
cache_life_time Cache time to live, in seconds.
cache_id A unique cache ID. This ID must contain all the parameters which may affect the result of cached code execution.
init_dir The name of directory for which the cache is valid. If "/", the cache is valid for all site directories.  
Optional. Current directory is used by default. 

See Also

Example



<?
// create an object
$obCache = new CPageCache; 

// 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.$IBLOCK_TYPE.$USER->GetUserGroupString(); 

// initialize buffered output
if($obCache->StartDataCache($life_time, $cache_id, "/")):
    // 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
    $obCache->EndDataCache(); 
endif;
?>