Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.164
diff -u -p -r1.164 module.inc
--- includes/module.inc	1 Nov 2009 22:10:07 -0000	1.164
+++ includes/module.inc	5 Nov 2009 06:17:10 -0000
@@ -69,10 +69,10 @@ function module_list($refresh = FALSE, $
       // locations in the file system. The ordering here must also be
       // consistent with the one used in module_implements().
       if ($bootstrap) {
-        $result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, name ASC");
+        $result = module_list_bootstrap();
       }
       else {
-        $result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, name ASC");
+        $result = module_list_enabled();
       }
       foreach ($result as $module) {
         if (file_exists($module->filename)) {
@@ -98,6 +98,47 @@ function module_list($refresh = FALSE, $
 }
 
 /**
+ * List modules required for bootstrap.
+ *
+ * @return
+ *   An array of modules which implement hook_boot() or hook_exit().
+ */
+function module_list_bootstrap() {
+  $list = module_build_list();
+  return $list['bootstrap'];
+}
+
+/**
+ * List all enabled modules.
+ *
+ * @return
+ *   An array of all enabled modules.
+ */
+function module_list_enabled() {
+  $list = module_build_list();
+  return $list['enabled'];
+}
+
+/**
+ * Generate and cache the lists of enabled modules required for module_list().
+ *
+ * @return
+ *   An associative array listing 'bootstrap' and 'enabled' modules.
+ */
+function module_build_list() {
+  $list = array();
+  if ($cached = cache_get('module_list')) {
+    $list = $cached->data;
+  }
+  else {
+    $list['bootstrap'] = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, name ASC")->fetchAll();
+    $list['enabled'] = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, name ASC")->fetchAll();
+    cache_set('module_list', $list);
+  }
+  return $list;
+}
+
+/**
  * Find dependencies any level deep and fill in required by information too.
  *
  * @param $files
@@ -236,12 +277,14 @@ function module_enable($module_list, $di
 
   if (!empty($invoke_modules)) {
     // Refresh the module list to exclude the disabled modules.
+    cache_clear_all('module_list', 'cache');
     module_list(TRUE);
     module_implements('', FALSE, TRUE);
     // Force to regenerate the stored list of hook implementations.
     registry_rebuild();
     // Refresh the schema to include the new enabled module.
     drupal_get_schema(NULL, TRUE);
+    
 
     // If any modules were newly installed, execute the hook for them.
     if (!$disable_modules_installed_hook && !empty($modules_installed)) {
@@ -296,6 +339,7 @@ function module_disable($module_list) {
 
   if (!empty($invoke_modules)) {
     // Refresh the module list to exclude the disabled modules.
+    cache_clear_all('module_list', 'cache');
     module_list(TRUE);
     module_implements('', FALSE, TRUE);
     // Invoke hook_modules_disabled before disabling modules,
