• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/composite/engine.php
  • Класс: BitrixMainCompositeEngine
  • Вызов: Engine::processPageContent
static function processPageContent($content)
{
	global $APPLICATION, $USER;

	$dividedData = self::getDividedPageData($content);
	$htmlCacheChanged = false;

	if (self::getUseHTMLCache())
	{
		$page = Page::getInstance();
		if ($page->isCacheable())
		{
			$cacheExists = $page->exists();
			$rewriteCache = $page->getMd5() !== $dividedData["md5"];
			if (self::getAutoUpdate() && self::getAutoUpdateTTL() > 0 && $cacheExists)
			{
				$mtime = $page->getLastModified();
				if ($mtime !== false && ($mtime + self::getAutoUpdateTTL()) > time())
				{
					$rewriteCache = false;
				}
			}

			$invalidateCache = self::getAutoUpdate() === false && self::isInvalidationRequest();

			$oldContent = null;
			if (!$cacheExists || $rewriteCache || $invalidateCache)
			{
				if ($invalidateCache || Locker::lock($page->getCacheKey()))
				{
					if ($cacheExists && Logger::isOn())
					{
						$oldContent = $page->read();
					}

					if ($page->getStorage() instanceof DataFileStorage)
					{
						$freeSpace = strlen($dividedData["static"]) + strlen($dividedData["md5"]);
						self::ensureFileQuota($freeSpace);
					}

					$success = $page->write($dividedData["static"], $dividedData["md5"]);

					if ($success)
					{
						$htmlCacheChanged = true;
						$page->setUserPrivateKey();
					}

					Locker::unlock($page->getCacheKey());
				}
			}

			$pageId = PageManager::register(
				$page->getCacheKey(),
				array(
					"CHANGED" => $htmlCacheChanged,
					"SIZE" => $page->getSize()
				)
			);

			if ($oldContent !== null)
			{
				Logger::log(
					array(
						"TYPE" => Logger::TYPE_CACHE_REWRITING,
						"MESSAGE" => $oldContent,
						"PAGE_ID" => $pageId
					)
				);
			}
		}
		else
		{
			$page->delete();

			return self::getAjaxError();
		}
	}

	if (self::getUseAppCache() == true) //Do we use html5 application cache?
	{
		AppCache::getInstance()->generate($dividedData["static"]);
	}
	else
	{
		AppCache::checkObsoleteManifest();
	}

	if (self::isAjaxRequest())
	{
		self::sendRandHeader();

		header("Content-Type: application/x-javascript; charset=".SITE_CHARSET);
		header("X-Bitrix-Composite: Ajax ".($htmlCacheChanged ? "(changed)" : "(stable)"));

		$content = array(
			"js" => array_unique($APPLICATION->arHeadScripts),
			"lang" => CJSCore::GetCoreMessages(),
			"css" => $APPLICATION->GetCSSArray(),
			"htmlCacheChanged" => $htmlCacheChanged,
			"isManifestUpdated" => AppCache::getInstance()->getIsModified(),
			"dynamicBlocks" => $dividedData["dynamic"],
			"spread" => array_map(array("CUtil", "JSEscape"), $APPLICATION->GetSpreadCookieUrls()),
		);

		$content = CUtil::PhpToJSObject($content);
	}
	else
	{
		$content = $dividedData["static"];
	}

	return $content;
}