Skip to content

Commit

Permalink
MDL-70233 cache: Disabled factory now gets writer from parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Peterburnett committed Apr 7, 2021
1 parent c7b4cf9 commit c2661e3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
32 changes: 32 additions & 0 deletions cache/classes/factory.php
Expand Up @@ -658,4 +658,36 @@ public static function get_administration_display_helper() : core_cache\administ
}
return self::$displayhelper;
}

/**
* Gets the cache_config_writer to use when caching is disabled.
* This should only be called from cache_factory_disabled.
*
* @return cache_config_writer
*/
public static function get_disabled_writer(): cache_config_writer {
global $CFG;

// Figure out if we are in a recursive loop using late static binding.
// This happens when get_disabled_writer is not overridden. We just want the default.
$loop = false;
if (!empty($CFG->alternative_cache_factory_class)) {
$loop = get_called_class() === $CFG->alternative_cache_factory_class;
}

if (!$loop && !empty($CFG->alternative_cache_factory_class)) {
// Get the class to use from the alternative factory.
$factoryinstance = new $CFG->alternative_cache_factory_class();
return $factoryinstance::get_disabled_writer();
} else {
// We got here from cache_factory_disabled.
// We should use the default writer here.
// Make sure we have a default config if needed.
if (!cache_config::config_file_exists()) {
cache_config_writer::create_default_configuration(true);
}

return new cache_config_writer();
}
}
}
8 changes: 4 additions & 4 deletions cache/disabledlib.php
Expand Up @@ -313,13 +313,13 @@ public function create_config_instance($writer = false) {
self::set_state(self::STATE_INITIALISING);
if ($class === 'cache_config_disabled') {
$configuration = $class::create_default_configuration();
$this->configs[$class] = new $class;
} else {
$configuration = false;
if (!cache_config::config_file_exists()) {
cache_config_writer::create_default_configuration(true);
}
// If we need a writer, we should get the classname from the generic factory.
// This is so alternative classes can be used if a different writer is required.
$this->configs[$class] = parent::get_disabled_writer();
}
$this->configs[$class] = new $class;
$this->configs[$class]->load($configuration);
}
self::set_state(self::STATE_READY);
Expand Down

0 comments on commit c2661e3

Please sign in to comment.