Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.136
diff -u -p -r1.136 filter.module
--- modules/filter/filter.module	20 Aug 2006 06:53:08 -0000	1.136
+++ modules/filter/filter.module	26 Aug 2006 02:38:49 -0000
@@ -388,7 +388,7 @@ function filter_admin_delete_submit($for
   db_query("UPDATE {comments} SET format = %d WHERE format = %d", $default, $form_values['format']);
   db_query("UPDATE {boxes} SET format = %d WHERE format = %d", $default, $form_values['format']);
 
-  cache_clear_all('filter:'. $form_values['format'], TRUE);
+  cache_clear_all('filter', $form_values['format'], TRUE);
   drupal_set_message(t('Deleted input format %format.', array('%format' => $form_values['name'])));
 
   return 'admin/settings/filters';
@@ -524,7 +524,7 @@ function filter_admin_format_form_submit
 
   db_query("UPDATE {filter_formats} SET cache = %d, name='%s', roles = '%s' WHERE format = %d", $cache, $name, $roles, $format);
 
-  cache_clear_all('filter:'. $format, TRUE);
+  cache_clear_all('filter', $format, TRUE);
 
   // If a new filter was added, return to the main list of filters. Otherwise, stay on edit filter page to show new changes.
   if ($new) {
@@ -582,7 +582,7 @@ function filter_admin_order_submit($form
   }
   drupal_set_message(t('The filter ordering has been saved.'));
 
-  cache_clear_all('filter:'. $form_values['format'], TRUE);
+  cache_clear_all('filter', $form_values['format'], TRUE);
 }
 
 /**
@@ -747,8 +747,8 @@ function check_markup($text, $format = F
     $format = filter_resolve_format($format);
 
     // Check for a cached version of this piece of text.
-    $id = 'filter:'. $format .':'. md5($text);
-    if ($cached = cache_get($id)) {
+    $id = $format .':'. md5($text);
+    if ($cached = cache_get('filter', $id)) {
       return $cached->data;
     }
 
@@ -774,7 +774,7 @@ function check_markup($text, $format = F
 
     // Store in cache with a minimum expiration time of 1 day.
     if ($cache) {
-      cache_set($id, $text, time() + (60 * 60 * 24));
+      cache_set('filter', $id, $text, time() + (60 * 60 * 24));
     }
   }
   else {
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.143
diff -u -p -r1.143 locale.module
--- modules/locale/locale.module	18 Aug 2006 18:58:46 -0000	1.143
+++ modules/locale/locale.module	26 Aug 2006 02:38:49 -0000
@@ -181,11 +181,11 @@ function locale($string) {
 
   // Store database cached translations in a static var.
   if (!isset($locale_t)) {
-    $cache = cache_get("locale:$locale");
+    $cache = cache_get('', "locale:$locale");
 
     if (!$cache) {
       locale_refresh_cache();
-      $cache = cache_get("locale:$locale");
+      $cache = cache_get('', "locale:$locale");
     }
     $locale_t = unserialize($cache->data);
   }
@@ -225,7 +225,7 @@ function locale($string) {
         }
       }
       // Clear locale cache in DB
-      cache_clear_all("locale:$locale");
+      cache_clear_all('', "locale:$locale");
     }
   }
 
@@ -246,7 +246,7 @@ function locale_refresh_cache() {
     while ($data = db_fetch_object($result)) {
       $t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
     }
-    cache_set("locale:$locale", serialize($t));
+    cache_set('', "locale:$locale", serialize($t));
   }
 }
 
Index: modules/node/content_types.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/content_types.inc,v
retrieving revision 1.5
diff -u -p -r1.5 content_types.inc
--- modules/node/content_types.inc	23 Aug 2006 04:40:56 -0000	1.5
+++ modules/node/content_types.inc	26 Aug 2006 02:38:49 -0000
@@ -281,7 +281,7 @@ function node_type_form_submit($form_id,
 
       if ($update_count) {
         drupal_set_message(t('Changed the content type of %update_count %posts from %old_type to %type.', array('%update_count' => $update_count, '%posts' => format_plural($update_count, 'post', 'posts'), '%old_type' => $type->old_type, '%type' => $type->type)));
-        cache_clear_all('filter:', TRUE);
+        cache_clear_all('filter', '*',  TRUE);
       }
     }
   }
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.12
diff -u -p -r1.12 system.install
--- modules/system/system.install	24 Aug 2006 06:27:41 -0000	1.12
+++ modules/system/system.install	26 Aug 2006 02:38:50 -0000
@@ -54,6 +54,33 @@ function system_install() {
         PRIMARY KEY (cid),
         INDEX expire (expire)
       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      db_query("CREATE TABLE {cache_filter} (
+        cid varchar(255) NOT NULL default '',
+        data longblob,
+        expire int NOT NULL default '0',
+        created int NOT NULL default '0',
+        headers text,
+        PRIMARY KEY (cid),
+        INDEX expire (expire)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      db_query("CREATE TABLE {cache_menu} (
+        cid varchar(255) NOT NULL default '',
+        data longblob,
+        expire int NOT NULL default '0',
+        created int NOT NULL default '0',
+        headers text,
+        PRIMARY KEY (cid),
+        INDEX expire (expire)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      db_query("CREATE TABLE {cache_page} (
+        cid varchar(255) NOT NULL default '',
+        data longblob,
+        expire int NOT NULL default '0',
+        created int NOT NULL default '0',
+        headers text,
+        PRIMARY KEY (cid),
+        INDEX expire (expire)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 
       db_query("CREATE TABLE {comments} (
         cid int NOT NULL auto_increment,
@@ -455,7 +482,34 @@ function system_install() {
         headers text,
         PRIMARY KEY (cid)
       )");
+      db_query("CREATE TABLE {cache_filter} (
+        cid varchar(255) NOT NULL default '',
+        data bytea,
+        expire int NOT NULL default '0',
+        created int NOT NULL default '0',
+        headers text,
+        PRIMARY KEY (cid)
+      )");
+      db_query("CREATE TABLE {cache_menu} (
+        cid varchar(255) NOT NULL default '',
+        data bytea,
+        expire int NOT NULL default '0',
+        created int NOT NULL default '0',
+        headers text,
+        PRIMARY KEY (cid)
+      )");
+      db_query("CREATE TABLE {cache_page} (
+        cid varchar(255) NOT NULL default '',
+        data bytea,
+        expire int NOT NULL default '0',
+        created int NOT NULL default '0',
+        headers text,
+        PRIMARY KEY (cid)
+      )");
       db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)");
+      db_query("CREATE INDEX {cache}_expire_idx ON {cache_filter} (expire)");
+      db_query("CREATE INDEX {cache}_expire_idx ON {cache_menu} (expire)");
+      db_query("CREATE INDEX {cache}_expire_idx ON {cache_page} (expire)");
 
       db_query("CREATE TABLE {comments} (
         cid serial,
@@ -3090,6 +3144,72 @@ function system_update_1007() {
   return $ret;
 }
 
+function system_update_1008() {
+ $ret = array();
+ switch ($GLOBALS['db_type']) {
+   case 'mysql':
+   case 'mysqli':
+     $ret[] = update_sql("CREATE TABLE {cache_filter} (
+       cid varchar(255) NOT NULL default '',
+       data longblob,
+       expire int NOT NULL default '0',
+       created int NOT NULL default '0',
+       headers text,
+       PRIMARY KEY (cid),
+       INDEX expire (expire)
+     ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+     $ret[] = update_sql("CREATE TABLE {cache_menu} (
+       cid varchar(255) NOT NULL default '',
+       data longblob,
+       expire int NOT NULL default '0',
+       created int NOT NULL default '0',
+       headers text,
+       PRIMARY KEY (cid),
+       INDEX expire (expire)
+     ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+     $ret[] = update_sql("CREATE TABLE {cache_page} (
+       cid varchar(255) NOT NULL default '',
+       data longblob,
+       expire int NOT NULL default '0',
+       created int NOT NULL default '0',
+       headers text,
+       PRIMARY KEY (cid),
+       INDEX expire (expire)
+     ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+     break;
+   case 'pgsql':
+     $ret[] = update_sql("CREATE TABLE {cache_filter} (
+       cid varchar(255) NOT NULL default '',
+       data bytea,
+       expire int NOT NULL default '0',
+       created int NOT NULL default '0',
+       headers text,
+       PRIMARY KEY (cid)
+     )");
+     $ret[] = update_sql("CREATE TABLE {cache_menu} (
+       cid varchar(255) NOT NULL default '',
+       data bytea,
+       expire int NOT NULL default '0',
+       created int NOT NULL default '0',
+       headers text,
+       PRIMARY KEY (cid)
+     )");
+     $ret[] = update_sql("CREATE TABLE {cache_page} (
+       cid varchar(255) NOT NULL default '',
+       data bytea,
+       expire int NOT NULL default '0',
+       created int NOT NULL default '0',
+       headers text,
+       PRIMARY KEY (cid)
+     )");
+     $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache_filter} (expire)");
+     $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache_menu} (expire)");
+     $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache_page} (expire)");
+     break;
+ }
+ return $ret;
+}
+
 /**
  * @} End of "defgroup updates-4.7-to-x.x"
  * The next series of updates should start at 2000.
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.661
diff -u -p -r1.661 user.module
--- modules/user/user.module	25 Aug 2006 09:01:12 -0000	1.661
+++ modules/user/user.module	26 Aug 2006 02:38:52 -0000
@@ -1461,7 +1461,7 @@ function user_edit_submit($form_id, $for
   user_module_invoke('submit', $form_values, $account, $category);
   user_save($account, $form_values, $category);
   // Delete that user's menu cache.
-  cache_clear_all('menu:'. $account->uid, TRUE);
+  cache_clear_all('menu', 'menu:'. $account->uid, TRUE);
   drupal_set_message(t('The changes have been saved.'));
   return 'user/'. $account->uid;
 }
Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.116
diff -u -p -r1.116 bootstrap.inc
--- includes/bootstrap.inc	25 Aug 2006 05:42:00 -0000	1.116
+++ includes/bootstrap.inc	26 Aug 2006 02:38:52 -0000
@@ -240,7 +240,7 @@ function drupal_get_filename($type, $nam
  */
 function variable_init($conf = array()) {
   // NOTE: caching the variables improves performance by 20% when serving cached pages.
-  if ($cached = cache_get('variables')) {
+  if ($cached = cache_get('default', 'variables')) {
     $variables = unserialize($cached->data);
   }
   else {
@@ -248,7 +248,7 @@ function variable_init($conf = array()) 
     while ($variable = db_fetch_object($result)) {
       $variables[$variable->name] = unserialize($variable->value);
     }
-    cache_set('variables', serialize($variables));
+    cache_set('default', 'variables', serialize($variables));
   }
 
   foreach ($conf as $name => $value) {
@@ -291,7 +291,7 @@ function variable_set($name, $value) {
   db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
   db_unlock_tables();
 
-  cache_clear_all('variables');
+  cache_clear_all('default', 'variables');
 
   $conf[$name] = $value;
 }
@@ -306,7 +306,7 @@ function variable_del($name) {
   global $conf;
 
   db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
-  cache_clear_all('variables');
+  cache_clear_all('default', 'variables');
 
   unset($conf[$name]);
 }
@@ -325,7 +325,7 @@ function page_get_cache() {
   $cache = NULL;
 
   if (!$user->uid && $_SERVER['REQUEST_METHOD'] == 'GET' && count(drupal_set_message()) == 0) {
-    $cache = cache_get($base_root . request_uri());
+    $cache = cache_get('page', $base_root . request_uri());
 
     if (empty($cache)) {
       ob_start();
Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.3
diff -u -p -r1.3 cache.inc
--- includes/cache.inc	5 Jul 2006 11:45:51 -0000	1.3
+++ includes/cache.inc	26 Aug 2006 02:38:52 -0000
@@ -4,21 +4,26 @@
 /**
  * Return data from the persistent cache.
  *
+ * @param $domain
+ *   The cache "domain" to store the data in. Valid initial values are 'filter', 
+ *   'menu', or 'page'. Use 'default' or '' for the default cache. 
  * @param $key
  *   The cache ID of the data to retrieve.
  */
-function cache_get($key) {
+function cache_get($domain, $key) {
   global $user;
 
+  $table = cache_get_table($domain);
+
   // Garbage collection necessary when enforcing a minimum cache lifetime
   $cache_flush = variable_get('cache_flush', 0);
   if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= time())) {
     // Time to flush old cache data
-    db_query("DELETE FROM {cache} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
+    db_query("DELETE FROM {%s} WHERE expire != %d AND expire <= %d", $table, CACHE_PERMANENT, $cache_flush);
     variable_set('cache_flush', 0);
   }
 
-  $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {cache} WHERE cid = '%s'", $key));
+  $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {%s} WHERE cid = '%s'", $table, $key));
   if (isset($cache->data)) {
     // If the data is permanent or we're not enforcing a minimum cache lifetime
     // always return the cached data.
@@ -47,6 +52,9 @@ function cache_get($key) {
 /**
  * Store data in the persistent cache.
  *
+ * @param $domain
+ *   The cache "domain" to store the data in. Valid initial values are 'filter', 
+ *   'menu', or 'page'. Use 'default' or '' for the default cache.  
  * @param $cid
  *   The cache ID of the data to store.
  * @param $data
@@ -62,11 +70,13 @@ function cache_get($key) {
  * @param $headers
  *   A string containing HTTP header information for cached pages.
  */
-function cache_set($cid, $data, $expire = CACHE_PERMANENT, $headers = NULL) {
-  db_lock_table('cache');
-  db_query("UPDATE {cache} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
+function cache_set($domain, $cid, $data, $expire = CACHE_PERMANENT, $headers = NULL) {
+  $table = cache_get_table($domain);
+
+  db_lock_table($table);
+  db_query("UPDATE {%s} SET data = '%s', created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $table, $data, time(), $expire, $headers, $cid);
   if (!db_affected_rows()) {
-    @db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
+    @db_query("INSERT INTO {%s} (cid, data, created, expire, headers) VALUES ('%s', '%s', %d, %d, '%s')", $table, $cid, $data, time(), $expire, $headers);
   }
   db_unlock_tables();
 }
@@ -74,6 +84,10 @@ function cache_set($cid, $data, $expire 
 /**
  * Expire data from the cache.
  *
+ * @param $domain
+ *   If set, the cache "domain" to delete from. Otherwise, all cache entries that
+ *   can expire are deleted from 'page' and 'menu' domains.
+ *
  * @param $cid
  *   If set, the cache ID to delete. Otherwise, all cache entries that can
  *   expire are deleted.
@@ -82,9 +96,20 @@ function cache_set($cid, $data, $expire 
  *   If set to TRUE, the $cid is treated as a substring to match rather than a
  *   complete ID.
  */
-function cache_clear_all($cid = NULL, $wildcard = FALSE) {
+function cache_clear_all($domain = NULL, $cid = NULL, $wildcard = FALSE) {
   global $user;
 
+  if (isset($domain)) {
+    $table = cache_get_table($domain);
+  }
+  else {
+    cache_clear_all('page');
+    cache_clear_all('menu', '*', TRUE);
+    cache_clear_all('filter');
+    cache_clear_all('default');
+    return;
+  }
+
   if (empty($cid)) {
     if (variable_get('cache_lifetime', 0)) {
       // We store the time in the current user's $user->cache variable which
@@ -101,22 +126,48 @@ function cache_clear_all($cid = NULL, $w
       else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) {
         // Clear the cache for everyone, cache_flush_delay seconds have
         // passed since the first request to clear the cache.
-        db_query("DELETE FROM {cache} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
+        db_query("DELETE FROM {%s} WHERE expire != %d AND expire < %d", $table, CACHE_PERMANENT, time());
         variable_set('cache_flush', 0);
       }
     }
     else {
       // No minimum cache lifetime, flush all temporary cache entries now.
-      db_query("DELETE FROM {cache} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
+      db_query("DELETE FROM {%s} WHERE expire != %d AND expire < %d", $table, CACHE_PERMANENT, time());
     }
   }
   else {
     if ($wildcard) {
-      db_query("DELETE FROM {cache} WHERE cid LIKE '%%%s%%'", $cid);
+      if ($cid == '*') {
+        db_query("DELETE FROM {%s}", $table);
+      }
+      else {
+        db_query("DELETE FROM {%s} WHERE cid LIKE '%%%s%%'", $table, $cid);
+      }
     }
     else {
-      db_query("DELETE FROM {cache} WHERE cid = '%s'", $cid);
+      db_query("DELETE FROM {%s} WHERE cid = '%s'", $table, $cid);
     }
   }
 }
 
+/**
+ * Helper function for cache functions. Maps a cahce "domain" to a database 
+ * table. Modules may define additional cache domains by creating a table 
+ * of the same type as {cache} and adding the domain to the 'cache_tables'
+ * variable.
+ *
+ * @param $domain
+ *   The cache "domain" is mapped to the name of a database table.  
+ *   Valid initial values are 'filter', 'menu', or 'page'. Use 'default or ''
+ *   (or any undefined domain) for the default cache.
+ */
+function cache_get_table($domain = '') {
+  static $cache_tables;
+
+  if (!isset($cache_tables)) {
+    $cache_tables = variable_get('cache_tables', array('filter' => 'cache_filter', 'menu' => 'cache_menu', 'page' => 'cache_page'));
+  }
+  return isset($cache_tables[$domain]) ? $cache_tables[$domain] : 'cache';
+}
+
+
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.566
diff -u -p -r1.566 common.inc
--- includes/common.inc	26 Aug 2006 00:23:12 -0000	1.566
+++ includes/common.inc	26 Aug 2006 02:38:53 -0000
@@ -1596,7 +1596,7 @@ function page_set_cache() {
       }
       ob_end_flush();
       if ($cache && $data) {
-        cache_set($base_root . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers());
+        cache_set('page', $base_root . request_uri(), $data, CACHE_TEMPORARY, drupal_get_headers());
       }
     }
   }
Index: includes/locale.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/locale.inc,v
retrieving revision 1.88
diff -u -p -r1.88 locale.inc
--- includes/locale.inc	18 Aug 2006 18:58:44 -0000	1.88
+++ includes/locale.inc	26 Aug 2006 02:38:53 -0000
@@ -486,7 +486,7 @@ function _locale_import_po($file, $lang,
   }
 
   // rebuild locale cache
-  cache_clear_all("locale:$lang");
+  cache_clear_all('default', "locale:$lang");
 
   // rebuild the menu, strings may have changed
   menu_rebuild();
Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.133
diff -u -p -r1.133 menu.inc
--- includes/menu.inc	20 Aug 2006 05:57:40 -0000	1.133
+++ includes/menu.inc	26 Aug 2006 02:38:54 -0000
@@ -206,14 +206,14 @@ function menu_get_menu() {
     // _menu_build() may indirectly call this function, so prevent infinite loops.
     $_menu['items'] = array();
 
-    $cid = "menu:$user->uid:$locale";
-    if ($cached = cache_get($cid)) {
+    $cid = "$user->uid:$locale";
+    if ($cached = cache_get('menu', $cid)) {
       $_menu = unserialize($cached->data);
     }
     else {
       _menu_build();
       // Cache the menu structure for this user, to expire after one day.
-      cache_set($cid, serialize($_menu), time() + (60 * 60 * 24));
+      cache_set('menu', $cid, serialize($_menu), time() + (60 * 60 * 24));
     }
 
     // Make sure items that cannot be cached are added.
@@ -585,9 +585,8 @@ function menu_in_active_trail_in_submenu
  */
 function menu_rebuild() {
   // Clear the page cache, so that changed menus are reflected for anonymous users.
-  cache_clear_all();
   // Also clear the menu cache.
-  cache_clear_all('menu:', TRUE);
+  cache_clear_all();
 
   _menu_build();
 
