Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bootstrap chicken and egg condition #50 #51

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions classes/cache_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,24 @@ private function generate_config_array(): array {
// Generate locks.
$locks = $this->generate_locks();

// Get the siteidentifier. Copies pattern from cache_config.
// Uses 'forcedcache' if not known.
if (!empty($CFG->siteidentifier)) {
$siteidentifier = md5((string) $CFG->siteidentifier);
} else {
$siteidentifier = 'forcedcache';
}

// Throw it all into an array and return.
return array(
'siteidentifier' => $siteidentifier,
$config = [
'stores' => $stores,
'modemappings' => $modemappings,
'definitions' => $definitions,
'definitionmappings' => $definitionmappings,
'locks' => $locks
);
];

// Get the siteidentifier. Copies pattern from cache_config.
// If the siteid is not yet known then we do not want it set which
// means the caches will be disabled further down the chain.
if (!empty($CFG->siteidentifier)) {
$config['siteidentifier'] = md5((string) $CFG->siteidentifier);
}

return $config;

}

/**
Expand Down
10 changes: 9 additions & 1 deletion classes/cache_factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ public function create_config_instance($writer = false) {
$this->configs[$class]->load();
}

$this->set_state(self::STATE_READY);
// We need the siteid in order to use the caches, but the siteid
// is also looked up from the caches so we have a chicken and egg
// situation in the bootstrap. This first time we configure the
// caches but disable them so the siteid can warm up correctly.
if (empty($CFG->siteidentifier)) {
brendanheywood marked this conversation as resolved.
Show resolved Hide resolved
$this->set_state(self::STATE_STORES_DISABLED);
} else {
$this->set_state(self::STATE_READY);
}

// Return the instance.
return $this->configs[$class];
Expand Down
Loading