Skip to content

Commit

Permalink
Merge pull request #51 from catalyst/siteid-fix
Browse files Browse the repository at this point in the history
Fix bootstrap chicken and egg condition #50
  • Loading branch information
brendanheywood authored Jun 13, 2024
2 parents 7f7e90b + a9c4c10 commit 049b0e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
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)) {
$this->set_state(self::STATE_STORES_DISABLED);
} else {
$this->set_state(self::STATE_READY);
}

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

0 comments on commit 049b0e4

Please sign in to comment.