Forums / National / Russian / Тех. поддержка / Вопрос про static $com_cache

Kopusha
#47024 2023-08-23 17:02
function cot_comments_count($ext_name, $code, $row = array())
{
	global $db, $db_com;
	static $com_cache = array();

	if (isset($com_cache[$ext_name][$code]))
	{
		return $com_cache[$ext_name][$code];
	}

	$cnt = 0;
	if (isset($row['com_count']))
	{
		$cnt = (int) $row['com_count'];
		$com_cache[$ext_name][$code] = $cnt;
	}
	else
	{
		$comments_join_columns = '';
		$comments_join_tables = '';
		$comments_join_where = '';
		/* == Hook == */
		foreach (cot_getextplugins('comments.count.query') as $pl)
		{
			include $pl;
		}
		/* ===== */
		$sql = $db->query("SELECT COUNT(*) $comments_join_columns
			FROM $db_com $comments_join_tables
			WHERE com_area = ? AND com_code = ? $comments_join_where",
			array($ext_name, $code));
		if ($sql->rowCount() == 1)
		{
			$cnt = (int) $sql->fetchColumn();
			$com_cache[$ext_name][$code] = $cnt;
		}
	}

	return $cnt;
}

Собственно код из мастер ветки

Такой вопрос - тут создается какой то кеш static $com_cache = array();
и в него пишуться данные и если они там есть то запрос к $sql не выполняется а 

        $cnt = (int) $row['com_count'];
        $com_cache[$ext_name][$code] = $cnt;

а если нет то $cnt = (int) $sql->fetchColumn(); и $com_cache[$ext_name][$code] = $cnt;
Это все вроде бы понимаю, но был бы благодарен за текстовые пояснения. Это кеш для сессии? Сколько он живет? и тд
Заранее спасибо!