• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/data/cache.php
  • Класс: BitrixMainDataCache
  • Вызов: Cache::clearCache
static function clearCache($full = false, $initDir = ''): bool
{
	if (($full !== true) && ($full !== false) && ($initDir === '') && is_string($full))
	{
		$initDir = $full;
		$full = true;
	}

	$res = true;

	if ($full === true)
	{
		$obCache = static::createInstance();
		$obCache->cleanDir($initDir, 'cache');
	}

	$path = MainLoader::getPersonal('cache' . $initDir);
	if (is_dir($path) && ($handle = opendir($path)))
	{
		while (($file = readdir($handle)) !== false)
		{
			if ($file === '.' || $file === '..')
			{
				continue;
			}

			if (is_dir($path . '/' . $file))
			{
				if (!static::clearCache($full, $initDir . '/' . $file))
				{
					$res = false;
				}
				else
				{
					@chmod($path . '/' . $file, BX_DIR_PERMISSIONS);
					//We suppress error handle here because there may be valid cache files in this dir
					@rmdir($path . '/' . $file);
				}
			}
			elseif ($full)
			{
				@chmod($path . '/' . $file, BX_FILE_PERMISSIONS);
				if (!unlink($path . '/' . $file))
				{
					$res = false;
				}
			}
			elseif (mb_substr($file, -4) === '.php')
			{
				$c = static::createInstance();
				if ($c->isCacheExpired($path . '/' . $file))
				{
					@chmod($path . '/' . $file, BX_FILE_PERMISSIONS);
					if (!unlink($path . '/' . $file))
					{
						$res = false;
					}
				}
			}
			else
			{
				//We should skip unknown file
				//it will be deleted with full cache cleanup
			}
		}
		closedir($handle);
	}

	return $res;
}