- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/file.php
- Класс: CFile
- Вызов: CFile::GetFromCache
static function GetFromCache($fileId, $realId = false)
{
global $DB;
$cache = MainApplication::getInstance()->getManagedCache();
$bucketSize = (int)CACHED_b_file_bucket_size;
if ($bucketSize <= 0)
{
$bucketSize = 10;
}
$bucket = (int)($fileId / $bucketSize);
$https = (int)MainContext::getCurrent()->getRequest()->isHttps();
$cacheId = self::CACHE_DIR . $https . (int)$realId . $bucket;
if ($cache->read(CACHED_b_file, $cacheId, self::CACHE_DIR))
{
$files = $cache->get($cacheId);
if (!isset($files[$fileId]))
{
// the trail of an incomplete bucket
if (!is_array($files))
{
$files = [];
}
if ($file = static::GetFromDb($fileId, $realId)->Fetch())
{
$files[$fileId] = $file;
static::CleanCache($fileId);
}
}
}
else
{
$files = [];
$minId = $bucket * $bucketSize;
$maxId = ($bucket + 1) * $bucketSize - 1;
$sql = "
SELECT f.*,
{$DB->DateToCharFunction("f.TIMESTAMP_X")} as TIMESTAMP_X,
NULL as VERSION_ORIGINAL_ID, '' as META
FROM b_file f
WHERE f.ID >= {$minId}
AND f.ID <= {$maxId}
";
if ($realId !== true)
{
$sql .= "
UNION
SELECT f.*,
{$DB->DateToCharFunction("f.TIMESTAMP_X")} as TIMESTAMP_X,
fv.ORIGINAL_ID as VERSION_ORIGINAL_ID, fv.META as META
FROM b_file f
INNER JOIN b_file_version fv ON fv.VERSION_ID = f.ID
WHERE fv.ORIGINAL_ID >= {$minId}
AND fv.ORIGINAL_ID <= {$maxId}
ORDER BY ID
";
}
$rs = $DB->Query($sql);
while ($file = $rs->fetch())
{
$originalId = ($file['VERSION_ORIGINAL_ID'] ?: $file["ID"]);
$files[$originalId] = $file;
}
// store SRC in cache
foreach ($files as $id => $file)
{
$files[$id]['SRC'] = static::GetFileSRC($file);
}
$cache->setImmediate($cacheId, $files);
}
return $files;
}