- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/component.php
- Класс: CBitrixComponent
- Вызов: CBitrixComponent::startResultCache
public function startResultCache($cacheTime = false, $additionalCacheID = false, $cachePath = false)
{
/** @global CMain $APPLICATION */
global $APPLICATION, $CACHE_MANAGER;
if (!$this->__bInited)
return null;
if ($this->arParams["CACHE_TYPE"] == "N" || ($this->arParams["CACHE_TYPE"] == "A" && COption::getOptionString("main", "component_cache_on", "Y") == "N"))
return true;
if ($cacheTime === false)
$cacheTime = intval($this->arParams["CACHE_TIME"] ?? 0);
$this->__cacheID = $this->getCacheID($additionalCacheID);
$this->__cachePath = $cachePath;
if ($this->__cachePath === false)
$this->__cachePath = $CACHE_MANAGER->getCompCachePath($this->__relativePath);
$this->__cache = BitrixMainDataCache::createInstance(['actual_data' => false]);
if ($this->__cache->startDataCache($cacheTime, $this->__cacheID, $this->__cachePath))
{
$this->__NavNum = $GLOBALS["NavNum"] ?? null;
$this->__currentCounters = self::$__componentCounter;
if (defined("BX_COMP_MANAGED_CACHE") && $this->__cache->isStarted())
$CACHE_MANAGER->startTagCache($this->__cachePath);
return true;
}
else
{
$arCache = $this->__cache->GetVars();
$this->arResult = $arCache["arResult"];
if (array_key_exists("templateCachedData", $arCache))
{
$templateCachedData = & $arCache["templateCachedData"];
if ($templateCachedData && is_array($templateCachedData))
{
if (array_key_exists("additionalCSS", $templateCachedData) && $templateCachedData["additionalCSS"] <> '')
{
$APPLICATION->SetAdditionalCSS($templateCachedData["additionalCSS"]);
if($this->__parent)
$this->__parent->addChildCSS($templateCachedData["additionalCSS"]);
}
if (array_key_exists("additionalJS", $templateCachedData) && $templateCachedData["additionalJS"] <> '')
{
$APPLICATION->AddHeadScript($templateCachedData["additionalJS"]);
if($this->__parent)
$this->__parent->addChildJS($templateCachedData["additionalJS"]);
}
if (array_key_exists("frames", $templateCachedData) && is_array($templateCachedData["frames"]))
{
foreach ($templateCachedData["frames"] as $frameState)
{
$frame = BitrixMainCompositeStaticArea::applyCachedData($frameState);
if ($this->__parent)
{
$this->__parent->addChildFrame($frame);
}
}
}
if (
array_key_exists("__children_frames", $templateCachedData) &&
is_array($templateCachedData["__children_frames"])
)
{
foreach ($templateCachedData["__children_frames"] as $frame)
{
BitrixMainCompositeStaticArea::applyCachedData($frame);
}
}
if (array_key_exists("frameMode", $templateCachedData))
{
$templateFrameMode = $templateCachedData["frameMode"];
if ($this->getRealFrameMode() !== false)
{
$this->setFrameMode($templateFrameMode);
}
if ($this->getRealFrameMode() === false)
{
$context = isset($templateCachedData["frameModeCtx"])
? "(from component cache) ".$templateCachedData["frameModeCtx"]
: $this->__name." - a cached template set frameMode=false";
$page = BitrixMainCompositePage::getInstance();
$page->giveNegativeComponentVote($context);
}
}
if (isset($templateCachedData["externalCss"]))
{
foreach ($templateCachedData["externalCss"] as $cssPath)
{
$APPLICATION->SetAdditionalCSS($cssPath);
//Check if parent component exists and plug css it to it's "collection"
if($this->__parent)
$this->__parent->addChildCSS($cssPath);
}
}
if (isset($templateCachedData["externalJs"]))
{
foreach ($templateCachedData["externalJs"] as $jsPath)
{
$APPLICATION->AddHeadScript($jsPath);
//Check if parent component exists and plug js it to it's "collection"
if($this->__parent)
$this->__parent->addChildJS($jsPath);
}
}
}
if (isset($templateCachedData["__editButtons"]))
{
foreach ($templateCachedData["__editButtons"] as $button)
{
if ($button[0] == 'AddEditAction')
$this->addEditAction($button[1], $button[2], $button[3], $button[4]);
else
$this->addDeleteAction($button[1], $button[2], $button[3], $button[4]);
}
}
if (isset($templateCachedData["__view"]))
{
foreach ($templateCachedData["__view"] as $view_id => $target)
foreach ($target as $view_content)
$APPLICATION->addViewContent($view_id, $view_content[0], $view_content[1]);
}
if (array_key_exists("__NavNum", $templateCachedData))
{
$GLOBALS["NavNum"]+= $templateCachedData["__NavNum"];
}
if (array_key_exists("__currentCounters", $templateCachedData))
{
foreach ($templateCachedData["__currentCounters"] as $componentName => $counter)
{
self::increaseComponentCounter($componentName, $counter);
}
}
if (array_key_exists("__children_css", $templateCachedData))
{
foreach ($templateCachedData["__children_css"] as $css_url)
$APPLICATION->setAdditionalCSS($css_url);
}
if (array_key_exists("__children_js", $templateCachedData))
{
foreach ($templateCachedData["__children_js"] as $js_url)
$APPLICATION->addHeadScript($js_url);
}
if (array_key_exists("__children_epilogs", $templateCachedData))
{
foreach ($templateCachedData["__children_epilogs"] as $component_epilog)
$this->includeComponentEpilog($component_epilog);
}
if (array_key_exists("component_epilog", $templateCachedData))
{
$this->includeComponentEpilog($templateCachedData["component_epilog"]);
}
}
return false;
}
}