### Eclipse Workspace Patch 1.0
#P [drupal.org] HEAD
Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.8
diff -u -r1.8 cache.inc
--- includes/cache.inc	15 Apr 2007 15:38:35 -0000	1.8
+++ includes/cache.inc	24 Apr 2007 17:21:40 -0000
@@ -2,7 +2,8 @@
 // $Id: cache.inc,v 1.8 2007/04/15 15:38:35 dries Exp $
 
 /**
- * Return data from the persistent cache.
+ * Return data from the persistent cache. Data may be stored as either plain text or as serialized data.
+ * cache_get will automatically return unserialized objects and arrays.
  *
  * @param $key
  *   The cache ID of the data to retrieve.
@@ -21,12 +22,15 @@
     variable_set('cache_flush', 0);
   }
 
-  $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {$table} WHERE cid = '%s'", $key));
+  $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {$table} WHERE cid = '%s'", $key));
   if (isset($cache->data)) {
     // If the data is permanent or we're not enforcing a minimum cache lifetime
     // always return the cached data.
     if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
       $cache->data = db_decode_blob($cache->data);
+      if ($cache->serialized) {
+        $cache->data = unserialize($cache->data);
+      }
     }
     // If enforcing a minimum cache lifetime, validate that the data is
     // currently valid for this user before we return it by making sure the
@@ -40,6 +44,9 @@
       }
       else {
         $cache->data = db_decode_blob($cache->data);
+        if ($cache->serialized) {
+          $cache->data = unserialize($cache->data);
+        }
       }
     }
     return $cache;
@@ -75,7 +82,8 @@
  * @param $cid
  *   The cache ID of the data to store.
  * @param $data
- *   The data to store in the cache. Complex data types must be serialized first.
+ *   The data to store in the cache. Complex data types will be automatically serialized before insertion.
+ *   Strings will be stored as plain text and not serialized.
  * @param $table
  *   The table $table to store the data in. Valid core values are 'cache_filter',
  *   'cache_menu', 'cache_page', or 'cache'.
@@ -91,10 +99,15 @@
  *   A string containing HTTP header information for cached pages.
  */
 function cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $headers = NULL) {
+  $serialized = 0;
+  if (is_object($data) || is_array($data)) {
+    $data = serialize($data);
+    $serialized = 1;
+  }
   db_lock_table($table);
-  db_query("UPDATE {$table} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
+  db_query("UPDATE {$table} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid);
   if (!db_affected_rows()) {
-    @db_query("INSERT INTO {$table} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
+    @db_query("INSERT INTO {$table} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized);
   }
   db_unlock_tables();
 }
Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.156
diff -u -r1.156 bootstrap.inc
--- includes/bootstrap.inc	15 Apr 2007 15:36:10 -0000	1.156
+++ includes/bootstrap.inc	24 Apr 2007 17:21:40 -0000
@@ -365,14 +365,14 @@
 function variable_init($conf = array()) {
   // NOTE: caching the variables improves performance by 20% when serving cached pages.
   if ($cached = cache_get('variables', 'cache')) {
-    $variables = unserialize($cached->data);
+    $variables = $cached->data;
   }
   else {
     $result = db_query('SELECT * FROM {variable}');
     while ($variable = db_fetch_object($result)) {
       $variables[$variable->name] = unserialize($variable->value);
     }
-    cache_set('variables', serialize($variables));
+    cache_set('variables', $variables);
   }
 
   foreach ($conf as $name => $value) {
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.350
diff -u -r1.350 theme.inc
--- includes/theme.inc	17 Apr 2007 07:19:38 -0000	1.350
+++ includes/theme.inc	24 Apr 2007 17:21:41 -0000
@@ -115,7 +115,7 @@
 function _theme_load_registry($theme, $theme_engine = NULL) {
   $cache = cache_get("theme_registry:$theme", 'cache');
   if (isset($cache->data)) {
-    $registry = unserialize($cache->data);
+    $registry = $cache->data;
   }
   else {
     $registry = _theme_build_registry($theme, $theme_engine);
@@ -128,7 +128,7 @@
  * Write the theme_registry cache into the database.
  */
 function _theme_save_registry($theme, $registry) {
-  cache_set("theme_registry:$theme", serialize($registry));
+  cache_set("theme_registry:$theme", $registry);
 }
 
 /**
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.166
diff -u -r1.166 locale.module
--- modules/locale/locale.module	15 Apr 2007 15:36:10 -0000	1.166
+++ modules/locale/locale.module	24 Apr 2007 17:21:41 -0000
@@ -208,7 +208,7 @@
       locale_refresh_cache();
       $cache = cache_get('locale:'. $language->language, 'cache');
     }
-    $locale_t = unserialize($cache->data);
+    $locale_t = $cache->data;
   }
 
   // We have the translation cached (if it is TRUE, then there is no
@@ -268,7 +268,7 @@
     while ($data = db_fetch_object($result)) {
       $t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
     }
-    cache_set('locale:'. $language->language, serialize($t));
+    cache_set('locale:'. $language->language, $t);
   }
 }
 
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.94
diff -u -r1.94 system.install
--- modules/system/system.install	17 Apr 2007 08:13:11 -0000	1.94
+++ modules/system/system.install	24 Apr 2007 17:21:41 -0000
@@ -219,6 +219,7 @@
         expire int NOT NULL default '0',
         created int NOT NULL default '0',
         headers text,
+        serialized int(1) NOT NULL default '0',
         PRIMARY KEY (cid),
         INDEX expire (expire)
       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
@@ -228,6 +229,7 @@
         expire int NOT NULL default '0',
         created int NOT NULL default '0',
         headers text,
+        serialized int(1) NOT NULL default '0',
         PRIMARY KEY (cid),
         INDEX expire (expire)
       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
@@ -237,6 +239,7 @@
         expire int NOT NULL default '0',
         created int NOT NULL default '0',
         headers text,
+        serialized int(1) NOT NULL default '0',
         PRIMARY KEY (cid),
         INDEX expire (expire)
       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
@@ -691,6 +694,7 @@
         expire int NOT NULL default '0',
         created int NOT NULL default '0',
         headers text,
+        serialized int(1) NOT NULL default '0',
         PRIMARY KEY (cid)
       )");
       db_query("CREATE TABLE {cache_filter} (
@@ -699,6 +703,7 @@
         expire int NOT NULL default '0',
         created int NOT NULL default '0',
         headers text,
+        serialized int(1) NOT NULL default '0',
         PRIMARY KEY (cid)
       )");
       db_query("CREATE TABLE {cache_page} (
@@ -707,6 +712,7 @@
         expire int NOT NULL default '0',
         created int NOT NULL default '0',
         headers text,
+        serialized int(1) NOT NULL default '0',
         PRIMARY KEY (cid)
       )");
       db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)");
@@ -3737,6 +3743,30 @@
 }
 
 /**
+ * Add serialized field to cache tables
+ */
+function system_update_6009() {
+  $ret = array();
+  
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      db_add_column($ret, 'cache', 'serialized', 'int(1)', array('default' => "'0'", 'not null' => TRUE));
+      db_add_column($ret, 'cache_filter', 'serialized', 'int(1)', array('default' => "'0'", 'not null' => TRUE));
+      db_add_column($ret, 'cache_page', 'serialized', 'int(1)', array('default' => "'0'", 'not null' => TRUE));
+      break;
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {cache} ADD serialized int(1) NOT NULL default '0'");
+      $ret[] = update_sql("ALTER TABLE {cache_filter} ADD serialized int(1) NOT NULL default '0'");
+      $ret[] = update_sql("ALTER TABLE {cache_page} ADD serialized int(1) NOT NULL default '0'");
+      break;
+  
+  }
+  
+  return $ret;
+}
+
+/**
  * @} End of "defgroup updates-5.x-to-6.x"
  * The next series of updates should start at 7000.
  */