diff --git a/includes/common.inc b/includes/common.inc
index d0649d7..78e018a 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -7117,10 +7115,27 @@ function drupal_implode_tags($tags) {
  * invokes a hook so that other modules' cache data can be cleared as well.
  */
 function drupal_flush_all_caches() {
-  // Change query-strings on css/js files to enforce reload for all users.
-  _drupal_flush_css_js();
+  // Ensure that all following rebuilds can rely on fresh entity information
+  // by resetting all static caches.
+  drupal_static_reset();
 
+  // Rebuild class registry and module information.
   registry_rebuild();
+
+  // Clear core cache tables. This is required to come first, so all following
+  // operations are not able to invoke API functions that reload stale
+  // information from the database cache (which in turn might be cached in a
+  // static variable).
+  // Don't clear cache_form - in-progress form submissions may break.
+  // Page cache is cleared separately below, after most rebuilds (especially
+  // menu rebuild) have been done.
+  foreach (array('cache', 'cache_bootstrap') as $table) {
+    cache_clear_all('*', $table, TRUE);
+  }
+
+  // Change query-strings on css/js files to enforce reload for all users.
+  _drupal_flush_css_js();
+  // CSS and JS caches may rely on custom module-provided stream wrappers.
   drupal_clear_css_cache();
   drupal_clear_js_cache();
 
@@ -7129,22 +7144,34 @@ function drupal_flush_all_caches() {
   system_rebuild_theme_data();
   drupal_theme_rebuild();
 
+  // Rebuilding node types requires fresh entity information, since node_menu()
+  // defines router items based on node types, so they need to be rebuilt before
+  // hook_menu() is invoked.
+  // @todo Replace with a hook_rebuild(); contributed modules potentially also
+  //   need to rebuild data before hook_menu() is invoked. Rebuilding logic
+  //   should not be contained in hook_menu(), since these are separate
+  //   operations, and menu_rebuild() might not invoke hook_menu() at all due to
+  //   the locking framework.
   node_types_rebuild();
-  // node_menu() defines menu items based on node types so it needs to come
-  // after node types are rebuilt.
+
+  // Rebuild the menu router. Many hook_menu() implementations register router
+  // items based on entity information.
   menu_rebuild();
 
   // Synchronize to catch any actions that were added or removed.
   actions_synchronize();
 
-  // Don't clear cache_form - in-progress form submissions may break.
-  // Ordered so clearing the page cache will always be the last action.
-  $core = array('cache', 'cache_filter', 'cache_bootstrap', 'cache_page');
-  $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
-  foreach ($cache_tables as $table) {
+  // Clear module caches. Some implementations of hook_flush_caches() are not
+  // only returning cache tables to flush, but additionally attempt to rebuild
+  // module data, which may rely on various core registries and caches.
+  // Therefore, invoke these last, after flushing and rebuilding core data.
+  foreach (module_invoke_all('flush_caches') as $table) {
     cache_clear_all('*', $table, TRUE);
   }
 
+  // Clear the page cache after all cache flushes and rebuilds.
+  cache_clear_all('*', 'cache_page', TRUE);
+
   // Rebuild the bootstrap module list. We do this here so that developers
   // can get new hook_boot() implementations registered without having to
   // write a hook_update_N() function.
diff --git a/includes/install.core.inc b/includes/install.core.inc
index a74dfdf..14139a0 100644
--- a/includes/install.core.inc
+++ b/includes/install.core.inc
@@ -1487,6 +1487,8 @@ function install_import_locales_remaining(&$install_state) {
  *   A message informing the user that the installation is complete.
  */
 function install_finished(&$install_state) {
+include_once DRUPAL_ROOT . '/sites/all/modules/devel/krumo/class.krumo.php';
+krumo(drupal_static(NULL));
   drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_distribution_name())), PASS_THROUGH);
   $messages = drupal_set_message();
   $output = '<p>' . st('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_profile_distribution_name())) . '</p>';
@@ -1495,7 +1497,7 @@ function install_finished(&$install_state) {
   // Flush all caches to ensure that any full bootstraps during the installer
   // do not leave stale cached data, and that any content types or other items
   // registered by the install profile are registered correctly.
-  drupal_flush_all_caches();
+//  drupal_flush_all_caches();
 
   // Remember the profile which was used.
   variable_set('install_profile', drupal_get_profile());
@@ -1515,6 +1517,7 @@ function install_finished(&$install_state) {
   // Will also trigger indexing of profile-supplied content or feeds.
   drupal_cron_run();
 
+//krumo(drupal_static(NULL));
   return $output;
 }
 
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 66fadcb..f4e7503 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -768,6 +768,13 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)
 }
 
 /**
+ * Implements hook_flush_caches().
+ */
+function filter_flush_caches() {
+  return array('cache_filter');
+}
+
+/**
  * Expands an element into a base element with text format selector attached.
  *
  * The form element will be expanded into two separate form elements, one
diff --git a/modules/node/node.module b/modules/node/node.module
index 78be97d..155bd70 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1954,9 +1954,6 @@ function node_menu() {
     'type' => MENU_CALLBACK,
   );
   // @todo Remove this loop when we have a 'description callback' property.
-  // Reset internal static cache of _node_types_build(), forces to rebuild the
-  // node type information.
-  node_type_cache_reset();
   foreach (node_type_get_types() as $type) {
     $type_url_str = str_replace('_', '-', $type->type);
     $items['node/add/' . $type_url_str] = array(
