diff --git a/cache/classes/factory.php b/cache/classes/factory.php
index 43f075b38fd..9eee85a11c7 100644
--- a/cache/classes/factory.php
+++ b/cache/classes/factory.php
@@ -103,7 +103,7 @@ class cache_factory {
      * An array of lock plugins.
      * @var array
      */
-    protected $lockplugins = null;
+    protected $lockplugins = array();
 
     /**
      * The current state of the cache API.
@@ -155,7 +155,7 @@ class cache_factory {
         $factory->stores = array();
         $factory->configs = array();
         $factory->definitions = array();
-        $factory->lockplugins = null; // MUST be null in order to force its regeneration.
+        $factory->lockplugins = array(); // MUST be null in order to force its regeneration.
         // Reset the state to uninitialised.
         $factory->state = self::STATE_UNINITIALISED;
     }
@@ -406,7 +406,7 @@ class cache_factory {
                         $definition = $instance->get_definition_by_id($id);
                         if (!$definition) {
                             throw new coding_exception('The requested cache definition does not exist.'. $id, $id);
-                        } else {
+                        } else if (!$this->is_disabled()) {
                             debugging('Cache definitions reparsed causing cache reset in order to locate definition.
                                 You should bump the version number to ensure definitions are reprocessed.', DEBUG_DEVELOPER);
                         }
@@ -442,6 +442,7 @@ class cache_factory {
      * @return cache_lock_interface
      */
     public function create_lock_instance(array $config) {
+        global $CFG;
         if (!array_key_exists('name', $config) || !array_key_exists('type', $config)) {
             throw new coding_exception('Invalid cache lock instance provided');
         }
@@ -450,8 +451,16 @@ class cache_factory {
         unset($config['name']);
         unset($config['type']);
 
-        if ($this->lockplugins === null) {
-            $this->lockplugins = get_plugin_list_with_class('cachelock', '', 'lib.php');
+        if (!isset($this->lockplugins[$type])) {
+            $pluginname = substr($type, 10);
+            $file = $CFG->dirroot."/cache/locks/{$pluginname}/lib.php";
+            if (file_exists($file) && is_readable($file)) {
+                require_once($file);
+            }
+            if (!class_exists($type)) {
+                throw new coding_exception('Invalid lock plugin requested.');
+            }
+            $this->lockplugins[$type] = $type;
         }
         if (!array_key_exists($type, $this->lockplugins)) {
             throw new coding_exception('Invalid cache lock type.');
diff --git a/cache/classes/helper.php b/cache/classes/helper.php
index 20e2f6d51ba..075dc416dff 100644
--- a/cache/classes/helper.php
+++ b/cache/classes/helper.php
@@ -511,6 +511,7 @@ class cache_helper {
      * Update the site identifier stored by the cache API.
      *
      * @param string $siteidentifier
+     * @return string The new site identifier.
      */
     public static function update_site_identifier($siteidentifier) {
         global $CFG;
@@ -519,9 +520,10 @@ class cache_helper {
         $factory = cache_factory::instance();
         $factory->updating_started();
         $config = $factory->create_config_instance(true);
-        $config->update_site_identifier($siteidentifier);
+        $siteidentifier = $config->update_site_identifier($siteidentifier);
         $factory->updating_finished();
         cache_factory::reset();
+        return $siteidentifier;
     }
 
     /**
@@ -530,11 +532,30 @@ class cache_helper {
      * @return string
      */
     public static function get_site_identifier() {
-        if (is_null(self::$siteidentifier)) {
-            $factory = cache_factory::instance();
+        global $CFG;
+        if (!is_null(self::$siteidentifier)) {
+            return self::$siteidentifier;
+        }
+        // If site identifier hasn't been collected yet attempt to get it from the cache config.
+        $factory = cache_factory::instance();
+        // If the factory is initialising then we don't want to try to get it from the config or we risk
+        // causing the cache to enter an infinite initialisation loop.
+        if (!$factory->is_initialising()) {
             $config = $factory->create_config_instance();
             self::$siteidentifier = $config->get_site_identifier();
         }
+        if (is_null(self::$siteidentifier)) {
+            // If the site identifier is still null then config isn't aware of it yet.
+            // We'll see if the CFG is loaded, and if not we will just use unknown.
+            // It's very important here that we don't use get_config. We don't want an endless cache loop!
+            if (!empty($CFG->siteidentifier)) {
+                self::$siteidentifier = self::update_site_identifier($CFG->siteidentifier);
+            } else {
+                // It's not being recorded in MUC's config and the config data hasn't been loaded yet.
+                // Likely we are initialising.
+                return 'unknown';
+            }
+        }
         return self::$siteidentifier;
     }
 
diff --git a/cache/locallib.php b/cache/locallib.php
index 4d6d745dfbc..e2b498e19ab 100644
--- a/cache/locallib.php
+++ b/cache/locallib.php
@@ -529,10 +529,12 @@ class cache_config_writer extends cache_config {
      * Update the site identifier stored by the cache API.
      *
      * @param string $siteidentifier
+     * @return string The new site identifier.
      */
     public function update_site_identifier($siteidentifier) {
         $this->siteidentifier = md5((string)$siteidentifier);
         $this->config_save();
+        return $this->siteidentifier;
     }
 }