Answer the question
In order to leave comments, you need to log in
How to work with php cache on the new 1C-Bitrix core?
Hello! On the old kernel I write like this:
$obCache = new \CPHPCache();
$cacheID = 'cache';
$cachePath = '/'.self::MODULE_ID.'/'.$cacheID;
if ($obCache->InitCache(3600, $cacheID, $cachePath)) {
$vars = $obCache->GetVars();
extract($vars);
} else if ($obCache->StartDataCache()) {
// кеш отсутствует
$obCache->EndDataCache(['result' => $result]);
}
Answer the question
In order to leave comments, you need to log in
use \Bitrix\Main\Data\cache;
$cache = cache::createInstance();
if( $cache->initCache( $ttl, $id, $id ) ){
$res = $cache->getVars();
$arRes = $res["arRes"];
}else{
$res = array();
try{
$cache->startDataCache( $ttl, $id, $id );
$cache->endDataCache( array(
"arRes" => $arRes
) );
}catch( SystemException $e ){
$cache->abortDataCache();
ShowError( $e->getMessage() );
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question