Documentation

StartDataCache

bool
CPageCache::StartDataCache(
 int TTL,
 string uniq_str,
 mixed initdir = false, 
 string basedir = "cache"
)

The method starts buffered HTML output, or emits cache content if it is not expired. If cache file has expired, the method returns "true" or "false" otherwise. Non-static method.

Parameters

ParameterDescription Available fr om version
TTL Cache file lifetime in seconds.
uniq_str Unique cache identifier. This idetifier must include all parameters that can affect the result of executed cached data.
initdir Folder that stores component cache, related to /bitrix/cache/. If "/", the cache will be valid for all site catalogs.
Optional. Default value - current catalog.
3.3.0
basedir Basic cache directory. By default equals to cache, meaning that all is saved in /BX_PERSONAL_ROOT/cache/, wh ere BX_PERSONAL_ROOT equals 'bitrix' by default.5.1.2

See Also

Example

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

// caching time - 30 minutes
$life_time = 30*60; 

// generate cache ID depending on all the parameters 
// that can affect the resulting HTML
$cache_id = $ELEMENT_ID.$IBLOCK_TYPE.$USER->GetUserGroupString(); 

// initialize buffering of printed data
if($obCache->StartDataCache($life_time, $cache_id, "/")):
    // select parameters of information block element fr om the data base 
    if($arIBlockElement = GetIBlockElement($ELEMENT_ID, $IBLOCK_TYPE)):
        echo "<pre>"; print_r($arIBlockElement); echo "</pre>";
    endif;
    // record the buffered result into cache file
    $obCache->EndDataCache(); 
endif;
?>


© «Bitrix24», 2001-2024
Up