function FileCache::getMultiple
Same name in other branches
- 8.9.x core/lib/Drupal/Component/FileCache/FileCache.php \Drupal\Component\FileCache\FileCache::getMultiple()
- 10 core/lib/Drupal/Component/FileCache/FileCache.php \Drupal\Component\FileCache\FileCache::getMultiple()
- 11.x core/lib/Drupal/Component/FileCache/FileCache.php \Drupal\Component\FileCache\FileCache::getMultiple()
Overrides FileCacheInterface::getMultiple
1 call to FileCache::getMultiple()
- FileCache::get in core/
lib/ Drupal/ Component/ FileCache/ FileCache.php - Gets data based on a filename.
File
-
core/
lib/ Drupal/ Component/ FileCache/ FileCache.php, line 77
Class
- FileCache
- Allows to cache data based on file modification dates.
Namespace
Drupal\Component\FileCacheCode
public function getMultiple(array $filepaths) {
$file_data = [];
$remaining_cids = [];
// First load from the static cache what we can.
foreach ($filepaths as $filepath) {
if (!file_exists($filepath)) {
continue;
}
$realpath = realpath($filepath);
// If the file exists but realpath returns nothing, it is using a stream
// wrapper, those are not supported.
if (empty($realpath)) {
continue;
}
$cid = $this->prefix . ':' . $this->collection . ':' . $realpath;
if (isset(static::$cached[$cid]) && static::$cached[$cid]['mtime'] == filemtime($filepath)) {
$file_data[$filepath] = static::$cached[$cid]['data'];
}
else {
// Collect a list of cache IDs that we still need to fetch from cache
// backend.
$remaining_cids[$cid] = $filepath;
}
}
// If there are any cache IDs left to fetch from the cache backend.
if ($remaining_cids && $this->cache) {
$cache_results = $this->cache
->fetch(array_keys($remaining_cids)) ?: [];
foreach ($cache_results as $cid => $cached) {
$filepath = $remaining_cids[$cid];
if ($cached['mtime'] == filemtime($filepath)) {
$file_data[$cached['filepath']] = $cached['data'];
static::$cached[$cid] = $cached;
}
}
}
return $file_data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.