Merge branch 'MDL-70368-cache-image-metadata' of https://github.com/brendanheywood/moodle

This commit is contained in:
Jun Pataleta 2022-10-21 10:57:18 +08:00 committed by Ilya Tregubov
commit 58a92364ed
3 changed files with 21 additions and 1 deletions

View File

@ -61,6 +61,7 @@ $string['cachedef_databasemeta'] = 'Database meta information';
$string['cachedef_eventinvalidation'] = 'Event invalidation';
$string['cachedef_externalbadges'] = 'External badges for particular user';
$string['cachedef_fontawesomeiconmapping'] = 'Mapping of icons for font awesome';
$string['cachedef_file_imageinfo'] = 'File image info eg dimensions';
$string['cachedef_suspended_userids'] = 'List of suspended users per course';
$string['cachedef_groupdata'] = 'Course group information';
$string['cachedef_h5p_content_type_translations'] = 'H5P content-type libraries translations';

View File

@ -557,4 +557,14 @@ $definitions = array(
'staticacceleration' => true,
'ttl' => 1800,
],
// Cache image dimensions.
'file_imageinfo' => [
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true,
'staticacceleration' => true,
'canuselocalstore' => true,
'staticaccelerationsize' => 100,
],
);

View File

@ -365,9 +365,18 @@ abstract class file_system {
return false;
}
$hash = $file->get_contenthash();
$cache = cache::make('core', 'file_imageinfo');
$info = $cache->get($hash);
if ($info !== false) {
return $info;
}
// Whilst get_imageinfo_from_path can use remote paths, it must download the entire file first.
// It is more efficient to use a local file when possible.
return $this->get_imageinfo_from_path($this->get_local_path_from_storedfile($file, true));
$info = $this->get_imageinfo_from_path($this->get_local_path_from_storedfile($file, true));
$cache->set($hash, $info);
return $info;
}
/**