Skip to content

Commit

Permalink
MDL-25290 cache: Made handling of cache locks when writing config mor…
Browse files Browse the repository at this point in the history
…e robust
  • Loading branch information
Sam Hemelryk committed Oct 7, 2012
1 parent 8dbfbd7 commit 573a6c8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions cache/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,19 @@ protected function config_save() {

// We need to create a temporary cache lock instance for use here. Remember we are generating the config file
// it doesn't exist and thus we can't use the normal API for this (it'll just try to use config).
$lockconf = reset($this->configlocks);
if ($lockconf === false) {
debugging('Your cache configuration file is out of date and needs to be refreshed.', DEBUG_DEVELOPER);
// Use the default
$lockconf = array(
'name' => 'cachelock_file_default',
'type' => 'cachelock_file',
'dir' => 'filelocks',
'default' => true
);
}
$factory = cache_factory::instance();
$locking = $factory->create_lock_instance(reset($this->configlocks));
$locking = $factory->create_lock_instance($lockconf);
if ($locking->lock('configwrite', 'config', true)) {
// Its safe to use w mode here because we have already acquired the lock.
$handle = fopen($cachefile, 'w');
Expand Down Expand Up @@ -515,12 +526,6 @@ public static function get_store_summaries() {
ksort($default);
$return = $return + $default;

foreach ($instance->get_mode_mappings() as $mapping) {
if (!array_key_exists($mapping['store'], $return)) {
continue;
}
$return[$mapping['store']]['mappings']++;
}
foreach ($instance->get_definition_mappings() as $mapping) {
if (!array_key_exists($mapping['store'], $return)) {
continue;
Expand Down Expand Up @@ -738,7 +743,6 @@ public static function get_add_store_form($plugin) {
$config = cache_config::instance();
$locks = array();
foreach ($config->get_locks() as $lock => $conf) {
debug($conf);
if (!empty($conf['default'])) {
$name = get_string($lock, 'cache');
} else {
Expand Down

0 comments on commit 573a6c8

Please sign in to comment.