F
F
faragly2015-08-11 14:05:59
1C-Bitrix
faragly, 2015-08-11 14:05:59

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]);
}

There is a /bitrix/modules/main/lib/data/cache.php file in the new core, but the example cannot be found, even on offsite. Who worked with the new d7, show an example of working with the cache.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Khizhniy, 2015-08-11
@faragly

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 question

Ask a Question

731 491 924 answers to any question