? modules/locale/locale.install.example Index: modules/archive/archive.module =================================================================== RCS file: /cvs/drupal/drupal/modules/archive/archive.module,v retrieving revision 1.91 diff -u -p -r1.91 archive.module --- modules/archive/archive.module 7 Aug 2006 15:04:14 -0000 1.91 +++ modules/archive/archive.module 8 Aug 2006 02:19:57 -0000 @@ -97,7 +97,7 @@ function archive_calendar() { $end_of_month = mktime(23, 59, 59, $month, $last, $year); - $cache = cache_get("archive:calendar:$day-$month-$year"); + $cache = cache_get('default', "archive:calendar:$day-$month-$year"); if (!empty($cache)) { return $cache->data; @@ -209,7 +209,7 @@ function archive_calendar() { $output .= "\n\n"; - cache_set("archive:calendar:$day-$month-$year", $output, CACHE_TEMPORARY); + cache_set('default', "archive:calendar:$day-$month-$year", $output, CACHE_TEMPORARY); return $output; } Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.132 diff -u -p -r1.132 filter.module --- modules/filter/filter.module 7 Aug 2006 15:04:14 -0000 1.132 +++ modules/filter/filter.module 8 Aug 2006 02:19:58 -0000 @@ -384,7 +384,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' => theme('placeholder', $form_values['name'])))); return 'admin/settings/filters'; @@ -523,7 +523,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) { @@ -581,7 +581,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); } /** @@ -746,8 +746,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; } @@ -773,7 +773,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.140 diff -u -p -r1.140 locale.module --- modules/locale/locale.module 7 Aug 2006 15:04:14 -0000 1.140 +++ modules/locale/locale.module 8 Aug 2006 02:19:58 -0000 @@ -176,11 +176,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); } @@ -220,7 +220,7 @@ function locale($string) { } } // Clear locale cache in DB - cache_clear_all("locale:$locale"); + cache_clear_all('', "locale:$locale"); } } @@ -241,7 +241,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.1 diff -u -p -r1.1 content_types.inc --- modules/node/content_types.inc 6 Aug 2006 23:06:56 -0000 1.1 +++ modules/node/content_types.inc 8 Aug 2006 02:19:58 -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' => theme('placeholder', $type->old_type), '%type' => theme('placeholder', $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.5 diff -u -p -r1.5 system.install --- modules/system/system.install 6 Aug 2006 23:00:42 -0000 1.5 +++ modules/system/system.install 8 Aug 2006 02:20:00 -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(11) NOT NULL default '0', + created int(11) 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(11) NOT NULL default '0', + created int(11) 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(11) NOT NULL default '0', + created int(11) NOT NULL default '0', + headers text, + PRIMARY KEY (cid), + INDEX expire (expire) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); db_query("CREATE TABLE {comments} ( cid int(10) 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, @@ -974,7 +1028,7 @@ function system_update_113() { } // Flush the menu cache: - cache_clear_all('menu:', TRUE); + cache_clear_all('menu', '', TRUE); return $ret; } @@ -3025,3 +3079,69 @@ function system_update_188() { return $ret; } + +function system_update_189() { + $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(11) NOT NULL default '0', + created int(11) 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(11) NOT NULL default '0', + created int(11) 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(11) NOT NULL default '0', + created int(11) 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; +} Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.650 diff -u -p -r1.650 user.module --- modules/user/user.module 7 Aug 2006 15:04:16 -0000 1.650 +++ modules/user/user.module 8 Aug 2006 02:20:01 -0000 @@ -1443,7 +1443,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.111 diff -u -p -r1.111 bootstrap.inc --- includes/bootstrap.inc 7 Aug 2006 15:04:13 -0000 1.111 +++ includes/bootstrap.inc 8 Aug 2006 02:20:01 -0000 @@ -240,7 +240,7 @@ function drupal_get_filename($type, $nam */ function variable_init($conf = array()) { // NOTE: caching the variables improves performance with 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 8 Aug 2006 02:20:01 -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,18 @@ 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', $cid, $wildcard); + cache_clear_all('menu', '', TRUE); + 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 +124,43 @@ 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); + 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.552 diff -u -p -r1.552 common.inc --- includes/common.inc 7 Aug 2006 15:04:13 -0000 1.552 +++ includes/common.inc 8 Aug 2006 02:20:02 -0000 @@ -1452,7 +1452,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.84 diff -u -p -r1.84 locale.inc --- includes/locale.inc 7 Aug 2006 15:04:13 -0000 1.84 +++ includes/locale.inc 8 Aug 2006 02:20:02 -0000 @@ -473,7 +473,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.132 diff -u -p -r1.132 menu.inc --- includes/menu.inc 31 Jul 2006 11:25:52 -0000 1.132 +++ includes/menu.inc 8 Aug 2006 02:20:03 -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();