Permalink
Browse files

MDL-34401 Cache the contents of version.php files

This saves many inclusions of version.php files.
  • Loading branch information...
1 parent ad3ed98 commit 9d6eb027b47b6fb1b50619d3d7e912fcedd2b338 @mudrd8mz mudrd8mz committed Feb 12, 2013
Showing with 30 additions and 10 deletions.
  1. +29 −9 lib/pluginlib.php
  2. +1 −1 lib/tests/pluginlib_test.php
View
@@ -2170,15 +2170,28 @@ public function full_path($relativepath) {
/**
* Load the data from version.php.
*
+ * @param bool $disablecache do not attempt to obtain data from the cache
* @return stdClass the object called $plugin defined in version.php
*/
- protected function load_version_php() {
+ protected function load_version_php($disablecache=false) {
+
+ $cache = cache::make('core', 'plugininfo_base');
+
+ $versionsphp = $cache->get('versions_php');
+
+ if (!$disablecache and $versionsphp !== false and isset($versionsphp[$this->component])) {
+ return $versionsphp[$this->component];
+ }
+
$versionfile = $this->full_path('version.php');
$plugin = new stdClass();
if (is_readable($versionfile)) {
include($versionfile);
}
+ $versionsphp[$this->component] = $plugin;
+ $cache->set('versions_php', $versionsphp);
+
return $plugin;
}
@@ -2722,13 +2735,6 @@ public function init_display_name() {
// do nothing, the name is set in self::get_plugins()
}
- /**
- * @see load_version_php()
- */
- protected function load_version_php() {
- return parent::load_version_php();
- }
-
public function is_enabled() {
$globalstates = self::get_global_states();
@@ -2876,9 +2882,20 @@ public function init_display_name() {
/**
* Load the data from version.php.
+ *
+ * @param bool $disablecache do not attempt to obtain data from the cache
* @return object the data object defined in version.php.
*/
- protected function load_version_php() {
+ protected function load_version_php($disablecache=false) {
+
+ $cache = cache::make('core', 'plugininfo_base');
+
+ $versionsphp = $cache->get('versions_php');
+
+ if (!$disablecache and $versionsphp !== false and isset($versionsphp[$this->component])) {
+ return $versionsphp[$this->component];
+ }
+
$versionfile = $this->full_path('version.php');
$module = new stdClass();
@@ -2889,6 +2906,9 @@ protected function load_version_php() {
if (!isset($module->version) and isset($plugin->version)) {
$module = $plugin;
}
+ $versionsphp[$this->component] = $module;
+ $cache->set('versions_php', $versionsphp);
+
return $module;
}
@@ -338,7 +338,7 @@ public function load_disk_version() {
$this->versiondisk = 2012030500;
}
- protected function load_version_php() {
+ protected function load_version_php($disablecache=false) {
return (object)array(
'version' => 2012030500,
'requires' => 2012010100,

0 comments on commit 9d6eb02

Please sign in to comment.