Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Кэширование своей переменной

John edited this page Feb 20, 2017 · 1 revision

Управляемый кэш

<?php
$cacheId = 'uniqueCacheId';  
$cacheTtl = '3600';  
 
$cache = \Bitrix\Main\Application::getInstance()->getManagedCache();  
 
if ($cache->read($cacheTtl, $cacheId)){  
   $data = $cache->get($cacheId);  // get our data
}else{  
   $data = '12345678'; 
   $cache->set($cacheId, $data);  // set our cache
} 

Обычный кэш

<?php
$сache = Bitrix\Main\Data\Cache::createInstance(); 
if ($сache->initCache($cacheTime, $cacheId, $cacheDir)){ 
    $result = $сache->getVars(); 
}elseif ($сache->startDataCache()){ 
    $result = array(); 
    // ... 
    if ($isInvalid) 
    { 
        $cache->abortDataCache(); 
    } 
    // ... 
    $сache->endDataCache($result); 
} 
Clone this wiki locally