Skip to content

Commit

Permalink
Fix bootstrap chicken and egg condition #50
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood authored and matthewhilton committed Jul 2, 2024
1 parent 2396096 commit 31e271e
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 @@ -113,23 +113,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 @@ -60,7 +60,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 31e271e

Please sign in to comment.