- Patch #627338 by catch: add a cache_bootstrap() bin for better performance/scalability.

merge-requests/26/head
Dries Buytaert 2009-11-10 22:06:09 +00:00
parent 0629cfa957
commit 3ccb55f2bd
8 changed files with 27 additions and 37 deletions

View File

@ -701,12 +701,12 @@ function drupal_get_filename($type, $name, $filename = NULL) {
*/
function variable_initialize($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
if ($cached = cache_get('variables', 'cache')) {
if ($cached = cache_get('variables', 'cache_bootstrap')) {
$variables = $cached->data;
}
else {
$variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
cache_set('variables', $variables);
cache_set('variables', $variables, 'cache_bootstrap');
}
foreach ($conf as $name => $value) {
@ -750,7 +750,7 @@ function variable_set($name, $value) {
db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();
cache_clear_all('variables', 'cache');
cache_clear_all('variables', 'cache_bootstrap');
$conf[$name] = $value;
}
@ -769,7 +769,7 @@ function variable_del($name) {
db_delete('variable')
->condition('name', $name)
->execute();
cache_clear_all('variables', 'cache');
cache_clear_all('variables', 'cache_bootstrap');
unset($conf[$name]);
}
@ -2005,7 +2005,7 @@ function _registry_check_code($type, $name = NULL) {
if (!isset($lookup_cache)) {
$lookup_cache = array();
if ($cache = cache_get('lookup_cache', 'cache_registry')) {
if ($cache = cache_get('lookup_cache', 'cache_bootstrap')) {
$lookup_cache = $cache->data;
}
}
@ -2022,7 +2022,7 @@ function _registry_check_code($type, $name = NULL) {
// changes to the lookup cache for this request.
if ($type == REGISTRY_WRITE_LOOKUP_CACHE) {
if ($cache_update_needed) {
cache_set('lookup_cache', $lookup_cache, 'cache_registry');
cache_set('lookup_cache', $lookup_cache, 'cache_bootstrap');
}
return;
}

View File

@ -36,9 +36,10 @@ function _cache_get_object($bin) {
* 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_field', 'cache_filter', 'cache_form', 'cache_menu', 'cache_page',
* 'cache_path', 'cache_registry', 'cache_update' or 'cache' for the default
* cache.
* 'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form',
* 'cache_menu', 'cache_page', 'cache_path', 'cache_update' or 'cache' for
* the default cache.
*
* @return The cache or FALSE on failure.
*/
function cache_get($cid, $bin = 'cache') {
@ -117,8 +118,8 @@ function cache_get_multiple(array &$cids, $bin = 'cache') {
* 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_field', 'cache_filter', 'cache_form', 'cache_menu', 'cache_page',
* 'cache_path', 'cache_registry', 'cache_update' or 'cache' for the default
* 'cache_bootstrap', 'cache_field', 'cache_filter', 'cache_form',
* 'cache_menu', 'cache_page', 'cache_update' or 'cache' for the default
* cache.
* @param $expire
* One of the following values:

View File

@ -6088,7 +6088,7 @@ function drupal_flush_all_caches() {
node_types_rebuild();
// 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_registry', 'cache_page');
$core = array('cache', 'cache_filter', 'cache_bootstrap', 'cache_page');
$cache_tables = array_merge(module_invoke_all('flush_caches'), $core);
foreach ($cache_tables as $table) {
cache_clear_all('*', $table, TRUE);

View File

@ -438,16 +438,16 @@ function module_implements($hook, $sort = FALSE, $reset = FALSE) {
// per request.
if ($reset) {
$implementations = array();
cache_set('module_implements', array());
cache_set('module_implements', array(), 'cache_bootstrap');
drupal_static_reset('module_hook_info');
drupal_static_reset('drupal_alter');
cache_clear_all('hook_info', 'cache');
cache_clear_all('hook_info', 'cache_bootstrap');
return;
}
// Fetch implementations from cache.
if (empty($implementations)) {
$implementations = cache_get('module_implements');
$implementations = cache_get('module_implements', 'cache_bootstrap');
if ($implementations === FALSE) {
$implementations = array();
}
@ -498,7 +498,7 @@ function module_hook_info() {
$hook_info = &drupal_static(__FUNCTION__, array());
if (empty($hook_info)) {
$cache = cache_get('hook_info');
$cache = cache_get('hook_info', 'cache_bootstrap');
if ($cache === FALSE) {
// Rebuild the cache and save it.
// We can't use module_invoke_all() here or it would cause an infinite
@ -519,7 +519,7 @@ function module_hook_info() {
$function($hook_info);
}
}
cache_set('hook_info', $hook_info);
cache_set('hook_info', $hook_info, 'cache_bootstrap');
}
else {
$hook_info = $cache->data;

View File

@ -83,7 +83,7 @@ function _registry_rebuild() {
$unchanged_resources = array();
$lookup_cache = array();
if ($cache = cache_get('lookup_cache', 'cache_registry')) {
if ($cache = cache_get('lookup_cache', 'cache_bootstrap')) {
$lookup_cache = $cache->data;
}
foreach ($lookup_cache as $key => $file) {
@ -96,12 +96,10 @@ function _registry_rebuild() {
module_implements('', FALSE, TRUE);
_registry_check_code(REGISTRY_RESET_LOOKUP_CACHE);
cache_clear_all('*', 'cache_registry', TRUE);
// We have some unchanged resources, warm up the cache - no need to pay
// for looking them up again.
if (count($unchanged_resources) > 0) {
cache_set('lookup_cache', $unchanged_resources, 'cache_registry');
cache_set('lookup_cache', $unchanged_resources, 'cache_bootstrap');
}
}

View File

@ -286,6 +286,10 @@ function update_fix_d7_requirements() {
db_create_table('date_formats', $schema['date_formats']);
db_create_table('date_format_locale', $schema['date_format_locale']);
$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.';
db_create_table('cache_bootstrap', $schema['cache_bootstrap']);
// Add column for locale context.
if (db_table_exists('locales_source')) {
db_add_field('locales_source', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The context this string applies to.'));

View File

@ -1149,7 +1149,7 @@ class DrupalWebTestCase extends DrupalTestCase {
*/
protected function refreshVariables() {
global $conf;
cache_clear_all('variables', 'cache');
cache_clear_all('variables', 'cache_bootstrap');
$conf = variable_initialize();
}

View File

@ -701,6 +701,8 @@ function system_schema() {
'primary key' => array('cid'),
);
$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'];
@ -709,8 +711,6 @@ function system_schema() {
$schema['cache_menu']['description'] = 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.';
$schema['cache_path'] = $schema['cache'];
$schema['cache_path']['description'] = 'Cache table for path alias lookup.';
$schema['cache_registry'] = $schema['cache'];
$schema['cache_registry']['description'] = 'Cache table for the code registry system to remember what code files need to be loaded on any given page.';
$schema['date_format_type'] = array(
'description' => 'Stores configured date format types.',
@ -1962,19 +1962,6 @@ function system_update_7006() {
),
'primary key' => array('filename'),
);
$schema['cache_registry'] = array(
'fields' => array(
'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'),
'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
'headers' => array('type' => 'text', 'not null' => FALSE),
'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)
),
'indexes' => array('expire' => array('expire')),
'primary key' => array('cid'),
);
db_create_table('cache_registry', $schema['cache_registry']);
db_create_table('registry', $schema['registry']);
db_create_table('registry_file', $schema['registry_file']);
registry_rebuild();