? drupal.form-state-cache.52.patch
? drupal.form-state-cache.55.patch
Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.48
diff -u -p -r1.48 cache.inc
--- includes/cache.inc	18 May 2010 18:26:30 -0000	1.48
+++ includes/cache.inc	7 Jul 2010 19:57:31 -0000
@@ -38,10 +38,8 @@ function _cache_get_object($bin) {
  * @param $cid
  *   The cache ID of the data to retrieve.
  * @param $bin
- *   The cache bin to store the data in. Valid core values are 'cache_block',
- *   'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form',
- *   'cache_menu', 'cache_page', 'cache_path', 'cache_update' or 'cache' for
- *   the default cache.
+ *   The cache bin to store the data in. See cache_set() for the list and
+ *   description of core bins.
  *
  * @return
  *   The cache or FALSE on failure.
@@ -74,9 +72,11 @@ function cache_get_multiple(array &$cids
  * structures that get flushed together. While it is not a problem for most
  * cache bins if the entries in them are flushed before their expire time, some
  * might break functionality or are extremely expensive to recalculate. These
- * will be marked with a (*). The other bins expired automatically by core.
- * Contributed modules can add additional bins and get them expired
- * automatically by implementing hook_flush_caches().
+ * are marked with a (*). The other bins are fully flushed during
+ * drupal_flush_all_caches() and all bins are pruned of expired entries during
+ * system_cron(). Contributed modules can add additional bins and implement
+ * hook_flush_caches() to have them flushed during drupal_flush_all_caches() and
+ * pruned during system_cron().
  *
  *  - cache: Generic cache storage bin (used for variables, theme registry,
  *  locale date, list of simpletest tests etc).
@@ -87,10 +87,6 @@ function cache_get_multiple(array &$cids
  *
  *  - cache_filter: Stores filtered pieces of content.
  *
- *  - cache_form(*): Stores multistep forms. Flushing this bin means that some
- *  forms displayed to users lose their state and the data already submitted
- *  to them.
- *
  *  - cache_menu: Stores the structure of visible navigation menus per page.
  *
  *  - cache_page: Stores generated pages for anonymous users. It is flushed
@@ -105,6 +101,11 @@ function cache_get_multiple(array &$cids
  *  installed on the current site. As this is different for (almost) every
  *  site, it's very expensive to recalculate for the update server.
  *
+ *  - form_state(*): Stores multistep forms. This bin is named without the
+ *  'cache_' prefix, because it stores data that cannot be regenerated: flushing
+ *  this bin means that some forms displayed to users lose their state and the
+ *  data already submitted to them.
+ *
  * The reasons for having several bins are as follows:
  *
  * - smaller bins mean smaller database tables and allow for faster selects and
@@ -121,10 +122,8 @@ function cache_get_multiple(array &$cids
  *   serialized before insertion.
  *   Strings will be stored as plain text and not serialized.
  * @param $bin
- *   The cache bin to store the data in. Valid core values are 'cache_block',
- *   'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form',
- *   'cache_menu', 'cache_page', 'cache_update' or 'cache' for the default
- *   cache.
+ *   The cache bin to store the data in. See above for the list and description
+ *   of core bins.
  * @param $expire
  *   One of the following values:
  *   - CACHE_PERMANENT: Indicates that the item should never be removed unless
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1191
diff -u -p -r1.1191 common.inc
--- includes/common.inc	7 Jul 2010 17:00:42 -0000	1.1191
+++ includes/common.inc	7 Jul 2010 19:57:35 -0000
@@ -6267,7 +6267,8 @@ function drupal_flush_all_caches() {
   menu_rebuild();
   node_types_rebuild();
 
-  // Don't clear cache_form - in-progress form submissions may break.
+  // The 'form_state' cache bin must not be flushed here. See the description
+  // of the cache bins in the cache_set() documentation for details.
   // 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);
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.476
diff -u -p -r1.476 form.inc
--- includes/form.inc	7 Jul 2010 17:56:42 -0000	1.476
+++ includes/form.inc	7 Jul 2010 19:57:40 -0000
@@ -465,12 +465,12 @@ function drupal_rebuild_form($form_id, &
  * Fetch a form from cache.
  */
 function form_get_cache($form_build_id, &$form_state) {
-  if ($cached = cache_get('form_' . $form_build_id, 'cache_form')) {
+  if ($cached = cache_get('form_' . $form_build_id, 'form_state')) {
     $form = $cached->data;
 
     global $user;
     if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && !$user->uid)) {
-      if ($cached = cache_get('form_state_' . $form_build_id, 'cache_form')) {
+      if ($cached = cache_get('form_state_' . $form_build_id, 'form_state')) {
         // Re-populate $form_state for subsequent rebuilds.
         $form_state = $cached->data + $form_state;
 
@@ -497,12 +497,12 @@ function form_set_cache($form_build_id, 
     if ($GLOBALS['user']->uid) {
       $form['#cache_token'] = drupal_get_token();
     }
-    cache_set('form_' . $form_build_id, $form, 'cache_form', REQUEST_TIME + $expire);
+    cache_set('form_' . $form_build_id, $form, 'form_state', REQUEST_TIME + $expire);
   }
 
   // Cache form state.
   if ($data = array_diff_key($form_state, array_flip(form_state_keys_no_cache()))) {
-    cache_set('form_state_' . $form_build_id, $data, 'cache_form', REQUEST_TIME + $expire);
+    cache_set('form_state_' . $form_build_id, $data, 'form_state', REQUEST_TIME + $expire);
   }
 }
 
@@ -746,8 +746,8 @@ function drupal_process_form($form_id, &
       // here, as we've finished with them. The in-memory copies are still
       // here, though.
       if (!variable_get('cache', 0) && !empty($form_state['values']['form_build_id'])) {
-        cache_clear_all('form_' . $form_state['values']['form_build_id'], 'cache_form');
-        cache_clear_all('form_state_' . $form_state['values']['form_build_id'], 'cache_form');
+        cache_clear_all('form_' . $form_state['values']['form_build_id'], 'form_state');
+        cache_clear_all('form_state_' . $form_state['values']['form_build_id'], 'form_state');
       }
 
       // If batches were set in the submit handlers, we process them now,
Index: includes/install.core.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.core.inc,v
retrieving revision 1.25
diff -u -p -r1.25 install.core.inc
--- includes/install.core.inc	2 Jul 2010 15:32:10 -0000	1.25
+++ includes/install.core.inc	7 Jul 2010 19:57:45 -0000
@@ -274,6 +274,7 @@ function install_begin_request(&$install
   require_once DRUPAL_ROOT . '/includes/cache.inc';
   require_once DRUPAL_ROOT . '/includes/cache-install.inc';
   $conf['cache_default_class'] = 'DrupalFakeCache';
+  $conf['cache_class_form_state'] = '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
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.487
diff -u -p -r1.487 system.install
--- modules/system/system.install	7 Jul 2010 05:59:14 -0000	1.487
+++ modules/system/system.install	7 Jul 2010 19:57:47 -0000
@@ -662,8 +662,6 @@ function system_schema() {
   );
   $schema['cache_bootstrap'] = $schema['cache'];
   $schema['cache_bootstrap']['description'] = 'Cache table for data required to bootstrap Drupal, may be routed to a shared memory cache.';
-  $schema['cache_form'] = $schema['cache'];
-  $schema['cache_form']['description'] = 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.';
   $schema['cache_page'] = $schema['cache'];
   $schema['cache_page']['description'] = 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.';
   $schema['cache_menu'] = $schema['cache'];
@@ -874,6 +872,9 @@ function system_schema() {
     ),
   );
 
+  $schema['form_state'] = $schema['cache'];
+  $schema['form_state']['description'] = 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.';
+
   $schema['history'] = array(
     'description' => 'A record of which {users} have read which {node}s.',
     'fields' => array(
@@ -2768,6 +2769,14 @@ function system_update_7059(&$sandbox) {
 }
 
 /**
+ * Rename {cache_form} to {form_state} to indicate that this table shouldn't
+ * be wiped out when flushing caches.
+ */
+function system_update_7060() {
+  db_rename_table('cache_form', 'form_state');
+}
+
+/**
  * @} End of "defgroup updates-6.x-to-7.x"
  * The next series of updates should start at 8000.
  */
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.946
diff -u -p -r1.946 system.module
--- modules/system/system.module	7 Jul 2010 17:56:42 -0000	1.946
+++ modules/system/system.module	7 Jul 2010 19:57:49 -0000
@@ -2805,7 +2805,7 @@ function system_cron() {
     }
   }
 
-  $core = array('cache', 'cache_filter', 'cache_page', 'cache_form', 'cache_menu');
+  $core = array('cache', 'cache_filter', 'cache_page', 'form_state', 'cache_menu');
   $cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
   foreach ($cache_tables as $table) {
     cache_clear_all(NULL, $table);
