? .project
? install_cache_change.patch
? module_implements_cache_rerolled-2.patch
? module_implements_cache_rerolled-3.patch
? module_implements_cache_rerolled-4-test.patch
? module_implements_cache_rerolled-5.patch
? module_implements_cache_rerolled-6.patch
? module_implements_cache_rerolled.patch
? sites/default/files
? sites/default/private
? sites/default/settings.php
Index: install.php
===================================================================
RCS file: /cvs/drupal/drupal/install.php,v
retrieving revision 1.204
diff -u -r1.204 install.php
--- install.php	11 Sep 2009 03:15:51 -0000	1.204
+++ install.php	13 Sep 2009 14:37:26 -0000
@@ -257,6 +257,13 @@
   drupal_load('module', 'filter');
   drupal_load('module', 'user');
 
+  // Load the cache infrastructure with the Fake Cache. Switch to the database cache
+  // later if possible.
+  require_once DRUPAL_ROOT . '/includes/cache.inc';
+  require_once DRUPAL_ROOT . '/includes/cache-install.inc';
+  $conf['cache_inc'] = 'includes/cache.inc';
+  $conf['cache_default_class'] = 'DrupalFakeCache';
+   
   // Prepare for themed output, if necessary. We need to run this at the
   // beginning of the page request to avoid a different theme accidentally
   // getting set.
@@ -271,8 +278,7 @@
     // Since we have a database connection, we use the normal cache system.
     // This is important, as the installer calls into the Drupal system for
     // the clean URL checks, so we should maintain the cache properly.
-    require_once DRUPAL_ROOT . '/includes/cache.inc';
-    $conf['cache_inc'] = 'includes/cache.inc';
+    unset($conf['cache_default_class']);
 
     // Initialize the database system. Note that the connection
     // won't be initialized until it is actually requested.
@@ -282,13 +288,6 @@
     $task = install_verify_completed_task();
   }
   else {
-    // Since no persistent storage is available yet, and functions that check
-    // for cached data will fail, we temporarily replace the normal cache
-    // system with a stubbed-out version that short-circuits the actual
-    // caching process and avoids any errors.
-    require_once DRUPAL_ROOT . '/includes/cache-install.inc';
-    $conf['cache_inc'] = 'includes/cache-install.inc';
-
     $task = NULL;
 
     // Since previous versions of Drupal stored database connection information
Index: update.php
===================================================================
RCS file: /cvs/drupal/drupal/update.php,v
retrieving revision 1.302
diff -u -r1.302 update.php
--- update.php	7 Sep 2009 15:43:54 -0000	1.302
+++ update.php	13 Sep 2009 14:37:26 -0000
@@ -291,6 +291,9 @@
   drupal_load('module', 'system');
   drupal_load('module', 'filter');
 
+  // Reset the module_implements() cache.
+  module_implements('', FALSE, TRUE);
+
   // Set up $language, since the installer components require it.
   drupal_language_initialize();
 
Index: includes/cache-install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache-install.inc,v
retrieving revision 1.3
diff -u -r1.3 cache-install.inc
--- includes/cache-install.inc	28 Jul 2009 12:13:46 -0000	1.3
+++ includes/cache-install.inc	13 Sep 2009 14:37:26 -0000
@@ -10,19 +10,23 @@
  * implementation during normal operations would have a negative impact
  * on performance.
  */
+class DrupalFakeCache implements DrupalCacheInterface {
+  function __construct($bin) {
+  }
 
-function cache_get($key, $table = 'cache') {
-  return FALSE;
-}
+  function get($cid) {
+    return FALSE;
+  }
 
-function cache_get_multiple(array &$cids, $bin = 'cache') {
-  return array();
-}
+  function getMultiple(&$cids) {
+    return array();
+  }
 
-function cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $headers = NULL) {
-  return;
-}
 
-function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
-  return;
+  function set($cid, $data, $expire = CACHE_PERMANENT, array $headers = NULL) {
+  }
+
+  function clear($cid = NULL, $wildcard = FALSE) {
+  }
+	
 }
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.988
diff -u -r1.988 common.inc
--- includes/common.inc	11 Sep 2009 15:12:29 -0000	1.988
+++ includes/common.inc	13 Sep 2009 14:37:29 -0000
@@ -2403,6 +2403,7 @@
 
   _registry_check_code(REGISTRY_WRITE_LOOKUP_CACHE);
   drupal_cache_system_paths();
+  module_implements_write_cache();
 }
 
 /**
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.157
diff -u -r1.157 module.inc
--- includes/module.inc	24 Aug 2009 00:14:18 -0000	1.157
+++ includes/module.inc	13 Sep 2009 14:37:29 -0000
@@ -14,7 +14,6 @@
   foreach (module_list(TRUE, $bootstrap) as $module) {
     drupal_load('module', $module);
   }
-  module_implements('', FALSE, TRUE);
 }
 
 /**
@@ -344,19 +343,46 @@
  *   An array with the names of the modules which are implementing this hook.
  */
 function module_implements($hook, $sort = FALSE, $refresh = FALSE) {
-  static $implementations;
-
+  $implementations = &drupal_static(__FUNCTION__, array());
   if ($refresh) {
     $implementations = array();
+    cache_set('module_implements', array());
     return;
   }
+  
+  if (empty($implementations)) {
+    // Since the size of the module_implements() cache is relatively small
+    // and is needed on every page, we store the information in a variable
+    // rather than using cache_set() and cache_get().
+    $implementations = cache_get('module_implements');
+    if($implementations === FALSE) {
+    	$implementations = array();
+    }
+    else {
+    	$implementations = $implementations->data;
+    }
+  }
 
   if (!isset($implementations[$hook])) {
     $implementations[$hook] = array();
     $list = module_list(FALSE, FALSE, $sort);
     foreach ($list as $module) {
       if (module_hook($module, $hook)) {
-        $implementations[$hook][] = $module;
+        $implementations[$hook][$module] = $module;
+        //cache_set('module_implements', $implementations);
+        // We added  something to the cache, so write it when we're done.
+        $GLOBALS['module_implements_cache_write'] = TRUE;
+      }
+    }
+  }
+  else {
+    foreach ($implementations[$hook] as $module) {
+      if (!module_hook($module, $hook)) {
+        // Ensure no undefined function errors for calling functions.
+        unset($implementations[$hook][$module]);
+        // Set the module_implements cache to an empty array, this will
+        // force a fresh rebuild in module_implements_write_cache().
+        cache_set('module_implements', array());
       }
     }
   }
@@ -371,6 +397,17 @@
 }
 
 /**
+ * Write to the module_implements() cache.
+ */
+function module_implements_write_cache() {
+  $implementations = &drupal_static('module_implements');
+  // Check wether we need to write the cache.
+  if (isset($GLOBALS['module_implements_cache_write'])) {
+    cache_set('module_implements', $implementations);
+  }
+}
+
+/**
  * Invoke a hook in a particular module.
  *
  * @param $module
