Для кеширования в 1С-Битрикс есть новый класс Bitrix\Main\Data\Cache почти ничем не отличается в обращении от старого CPHPCache .
Пример старого API:
$cache = new \CPHPCache(); if ($cache->InitCache($cacheTime, $cacheId, $cacheDir)) { $result = $cache->GetVars(); } elseif($cache->StartDataCache()) { $result = array(); // ... if ($isInvalid) { $cache->AbortDataCache(); } // ... $cache->EndDataCache($result); }
Пример API D7:
$cache = \Bitrix\Main\Data\Cache::createInstance(); if ($cache->initCache($cacheTime, $cacheId, $cacheDir)) { $result = $cache->getVars(); } elseif ($cache->startDataCache()) { $result = array(); // ... if ($isInvalid) { $cache->abortDataCache(); } // ... $cache->endDataCache($result); }
Пример тегированного кеша на D7:
$cacheManager = \Bitrix\Main\Application::getInstance()->getTaggedCache(); $cacheManager->startTagCache('/path_cache'); $cacheManager->registerTag('tag'); $cacheManager->endTagCache(); //Очистить по тегу //$cacheManager->clearByTag('tag');
Добавить комментарий