MDL-70233 cache: Disabled factory now gets writer from parent

This commit is contained in:
Peter Burnett 2021-04-07 10:33:06 +10:00
parent f0eb6a5729
commit 93c0dc8ec4
2 changed files with 36 additions and 4 deletions

View File

@ -658,4 +658,36 @@ class cache_factory {
}
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();
}
}
}

View File

@ -313,13 +313,13 @@ class cache_factory_disabled extends cache_factory {
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);