A
A
Anton2019-07-06 14:41:17
1C-Bitrix
Anton, 2019-07-06 14:41:17

Caching when using api - how?

For example,

require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");
$arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM","PROPERTY_*");//IBLOCK_ID и ID обязательно должны быть указаны, см. описание arSelectFields выше
$arFilter = Array("IBLOCK_ID"=>IntVal($yvalue), "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y");
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>50), $arSelect);
while($ob = $res->GetNextElement()){ 
 $arFields = $ob->GetFields();  
print_r($arFields);
 $arProps = $ob->GetProperties();
print_r($arProps);
}

and fasten the layout)
How to cache and check that it really works, share working examples?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2019-07-07
@winer

CPhpCache - a class from the old API for caching PHP variables and HTML script results. See examples on the documentation page.
In D7, the analogue is \Bitrix\Main\Data\Cache

use \Bitrix\Main\Data\Cache;

$cache = Cache::createInstance(); // получаем экземпляр класса
if ($cache->initCache(7200, "cache_key")) { // проверяем кеш и задаём настройки
    $vars = $cache->getVars(); // достаем переменные из кеша
}
elseif ($cache->startDataCache()) {
    // некоторые действия...
    $cache->endDataCache(array("key" => "value")); // записываем в кеш
}

Take a look at the Bitrix Framework Developer course . There is a search there , with the help of which you can find quite a few articles about caching with examples.
To check the cache, you can use the debug tools . With their help, you can find out the cache usage within the hit. You can use the " Performance Monitor
" module . To do this, you need to enable the parameters Log cache and Enable monitor . The module will collect data for a given period of time. In the future, this data can be viewed on the administrative pages of the module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question