Skip to content

Commit

Permalink
Merge branch 'MDL-70368-cache-image-metadata' of https://github.com/b…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta authored and ilyatregubov committed Oct 21, 2022
2 parents 492662a + fe88783 commit 58a9236
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions lang/en/cache.php
Expand Up @@ -61,6 +61,7 @@
$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';
Expand Down
10 changes: 10 additions & 0 deletions lib/db/caches.php
Expand Up @@ -557,4 +557,14 @@
'staticacceleration' => true,
'ttl' => 1800,
],

// Cache image dimensions.
'file_imageinfo' => [
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'simpledata' => true,
'staticacceleration' => true,
'canuselocalstore' => true,
'staticaccelerationsize' => 100,
],
);
11 changes: 10 additions & 1 deletion lib/filestorage/file_system.php
Expand Up @@ -365,9 +365,18 @@ public function get_imageinfo(stored_file $file) {
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;
}

/**
Expand Down

0 comments on commit 58a9236

Please sign in to comment.