• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/cache_files.php
  • Класс: CPHPCacheFiles
  • Вызов: CPHPCacheFiles::DelayedDelete
static function DelayedDelete($count = 1, $level = 1)
{
	global $DB;

	$etime = time()+2;
	for($i = 0; $i < $count; $i++)
	{
		CPHPCacheFiles::DeleteOneDir($etime);
		if(time() > $etime)
			break;
	}

	//try to adjust cache cleanup speed to cache cleanups
	$rs = $DB->Query("SELECT * from b_cache_tag WHERE TAG='**'");
	if($ar = $rs->Fetch())
	{
		$last_count = intval($ar["RELATIVE_PATH"]);
		if(preg_match("/:(\d+)$/", $ar["RELATIVE_PATH"], $m))
			$last_time = intval($m[1]);
		else
			$last_time = 0;
	}
	else
	{
		$last_time = 0;
		$last_count = 0;
	}
	$bWasStatRecFound = is_array($ar);

	$rs = $DB->Query("SELECT count(1) CNT from b_cache_tag WHERE TAG='*'");
	if($ar = $rs->Fetch())
		$this_count = $ar["CNT"];
	else
		$this_count = 0;

	$delta = $this_count - $last_count;
	if($delta > 0)
	{
		if($last_time > 0)
			$time_step = time()-$last_time;
		if($time_step <= 0)
			$time_step = 1;
		$count = intval($this_count*$time_step/3600)+1; //Rest of the queue in an hour
	}
	elseif($count < 1)
	{
		$count = 1;
	}

	if($bWasStatRecFound)
	{
		if($last_count != $this_count)
			$DB->Query("UPDATE b_cache_tag SET RELATIVE_PATH='".$this_count.":".time()."' WHERE TAG='**'");
	}
	else
	{
		$DB->Query("INSERT INTO b_cache_tag (TAG, RELATIVE_PATH) VALUES ('**', '".$this_count.":".time()."')");
	}

	if($this_count > 0)
		return "CPHPCacheFiles::DelayedDelete(".$count.");";
	else
		return "";
}