MDL-37683 cache: siteidentifier is now included in the keys

This commit is contained in:
Sam Hemelryk 2013-02-06 13:45:17 +13:00
parent 1dd6835d8c
commit e0d9b7c0d4
11 changed files with 140 additions and 12 deletions

View file

@ -1577,5 +1577,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2013021100.01);
}
if ($oldversion < 2013021800.00) {
// Add the site identifier to the cache config's file.
$siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier'));
cache_helper::update_site_identifier($siteidentifier);
// Main savepoint reached.
upgrade_main_savepoint(true, 2013021800.00);
}
return true;
}

View file

@ -1327,6 +1327,9 @@ function set_config($name, $value, $plugin=NULL) {
$DB->insert_record('config', $config, false);
}
}
if ($name === 'siteidentifier') {
cache_helper::update_site_identifier($value);
}
cache_helper::invalidate_by_definition('core', 'config', array(), 'core');
} else { // plugin scope
if ($id = $DB->get_field('config_plugins', 'id', array('name'=>$name, 'plugin'=>$plugin))) {
@ -1360,6 +1363,8 @@ function set_config($name, $value, $plugin=NULL) {
* If called with 2 parameters it will return a string single
* value or false if the value is not found.
*
* @static $siteidentifier The site identifier is not cached. We use this static cache so
* that we need only fetch it once per request.
* @param string $plugin full component name
* @param string $name default NULL
* @return mixed hash-like object or single value, return false no config found
@ -1367,6 +1372,8 @@ function set_config($name, $value, $plugin=NULL) {
function get_config($plugin, $name = NULL) {
global $CFG, $DB;
static $siteidentifier = null;
if ($plugin === 'moodle' || $plugin === 'core' || empty($plugin)) {
$forced =& $CFG->config_php_settings;
$iscore = true;
@ -1380,8 +1387,28 @@ function get_config($plugin, $name = NULL) {
$iscore = false;
}
if (!empty($name) && array_key_exists($name, $forced)) {
return (string)$forced[$name];
if ($siteidentifier === null) {
try {
// This may fail during installation.
// If you have a look at {@link initialise_cfg()} you will see that this is how we detect the need to
// install the database.
$siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier'));
} catch (dml_exception $ex) {
// It's failed. We'll use this oppertunity to disable cache stores so that we don't inadvertingly start using
// old caches. People should delete there moodledata dirs when reinstalling the database... but they don't.
cache_factory::disable_stores();
// Set siteidentifier to false. We don't want to trip this continually.
$siteidentifier = false;
throw $ex;
}
}
if (!empty($name)) {
if (array_key_exists($name, $forced)) {
return (string)$forced[$name];
} else if ($name === 'siteidentifier' && $plugin == 'core') {
return $siteidentifier;
}
}
$cache = cache::make('core', 'config');
@ -1405,6 +1432,10 @@ function get_config($plugin, $name = NULL) {
return false;
}
if ($plugin === 'core') {
$result['siteidentifier'] = $siteidentifier;
}
foreach ($forced as $key => $value) {
if (is_null($value) or is_array($value) or is_object($value)) {
// we do not want any extra mess here, just real settings that could be saved in db

View file

@ -1448,8 +1448,9 @@ function install_core($version, $verbose) {
print_upgrade_part_end(null, true, $verbose);
// Reset the cache, this returns it to a normal operation state.
cache_factory::reset();
// Purge all caches. They're disabled but this ensures that we don't have any persistent data just in case something
// during installation didn't use APIs.
cache_helper::purge_all();
} catch (exception $ex) {
upgrade_handle_exception($ex);
}
@ -1536,8 +1537,8 @@ function upgrade_noncore($verbose) {
// upgrade all plugins types
try {
// Disable the use of cache stores here. We will reset the factory after we've performed the installation.
// This ensures that we don't permanently cache anything during installation.
// Disable the use of cache stores here.
// We don't reset this, the site can live without proper caching for life of this request.
cache_factory::disable_stores();
$plugintypes = get_plugin_types();
@ -1546,8 +1547,6 @@ function upgrade_noncore($verbose) {
}
// Update cache definitions. Involves scanning each plugin for any changes.
cache_helper::update_definitions();
// Reset the cache system to a normal state.
cache_factory::reset();
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}