From a9c4c10b24a84b9e98f75dd1654295d0bd4a6f63 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Wed, 12 Jun 2024 10:26:44 +1000 Subject: [PATCH] Fix bootstrap chicken and egg condition #50 --- classes/cache_config.php | 23 ++++++++++++----------- classes/cache_factory.php | 10 +++++++++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/classes/cache_config.php b/classes/cache_config.php index 8f21b9d..c68e7bc 100644 --- a/classes/cache_config.php +++ b/classes/cache_config.php @@ -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; + } /** diff --git a/classes/cache_factory.php b/classes/cache_factory.php index 0fb8c6a..97df30b 100644 --- a/classes/cache_factory.php +++ b/classes/cache_factory.php @@ -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];