• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/data/cache.php
  • Класс: BitrixMainDataCache
  • Вызов: Cache::initCache
public function initCache($ttl, $uniqueString, $initDir = false, $baseDir = 'cache')
{
	if ($initDir === false)
	{
		$initDir = 'default';
	}

	$personalRoot = MainApplication::getPersonalRoot();
	$this->baseDir = $personalRoot . '/' . $baseDir . '/';
	$this->initDir = $initDir;
	$this->filename = '/' . $this->getPath($uniqueString);
	$this->ttl = $ttl;
	$this->uniqueString = $uniqueString;
	$this->vars = false;

	if ($ttl <= 0 || $this->forceRewriting || static::shouldClearCache())
	{
		return false;
	}

	$data = ['CONTENT' => '', 'VARS' => ''];
	if (!$this->cacheEngine->read($data, $this->baseDir, $this->initDir, $this->filename, $this->ttl))
	{
		return false;
	}

	if (!is_array($data) || empty($data) || !isset($data['CONTENT']) || !isset($data['VARS']))
	{
		return false;
	}

	if (static::$showCacheStat)
	{
		$read = 0;
		$path = '';
		if ($this->cacheEngine instanceof ICacheEngineStat)
		{
			$read = $this->cacheEngine->getReadBytes();
			$path = $this->cacheEngine->getCachePath();
		}
		elseif ($this->cacheEngine instanceof ICacheBackend)
		{
			/** @noinspection PhpUndefinedFieldInspection */
			$read = $this->cacheEngine->read;

			/** @noinspection PhpUndefinedFieldInspection */
			$path = $this->cacheEngine->path;
		}

		DiagCacheTracker::addCacheStatBytes($read);
		DiagCacheTracker::add($read, $path, $this->baseDir, $this->initDir, $this->filename, 'R');
	}

	$this->content = $data['CONTENT'];
	$this->vars = $data['VARS'];

	return true;
}