diff --git a/cache/classes/definition.php b/cache/classes/definition.php index f0187648595..62732f737ce 100644 --- a/cache/classes/definition.php +++ b/cache/classes/definition.php @@ -314,7 +314,7 @@ class cache_definition { $requiremultipleidentifiers = false; $requirelockingread = false; $requirelockingwrite = false; - $requiresearchable = ($mode === cache_store::MODE_SESSION) ? true : false;; + $requiresearchable = ($mode === cache_store::MODE_SESSION) ? true : false; $maxsize = null; $overrideclass = null; $overrideclassfile = null; diff --git a/cache/classes/helper.php b/cache/classes/helper.php index 3e1d7edd6e7..45fe789300c 100644 --- a/cache/classes/helper.php +++ b/cache/classes/helper.php @@ -596,8 +596,10 @@ class cache_helper { } $definition = $factory->create_definition($definitionarray['component'], $definitionarray['area']); $stores = $config->get_stores_for_definition($definition); + // Turn them into store instances. + $stores = self::initialise_cachestore_instances($stores, $definition); // Initialise all of the stores used for that definition. - foreach (self::initialise_cachestore_instances($stores, $definition) as $store) { + foreach ($stores as $store) { // If the store doesn't support searching we can skip it. if (!($store instanceof cache_is_searchable)) { debugging('Cache stores used for session definitions should ideally be searchable.', DEBUG_DEVELOPER); diff --git a/cache/classes/loaders.php b/cache/classes/loaders.php index 18dcdfe65b2..9f7dc79bcca 100644 --- a/cache/classes/loaders.php +++ b/cache/classes/loaders.php @@ -752,7 +752,7 @@ class cache implements cache_loader { public function delete($key, $recurse = true) { $parsedkey = $this->parse_key($key); $this->delete_from_persist_cache($parsedkey); - if ($recurse && !empty($this->loader)) { + if ($recurse && $this->loader !== false) { // Delete from the bottom of the stack first. $this->loader->delete($key, $recurse); } @@ -774,7 +774,7 @@ class cache implements cache_loader { $this->delete_from_persist_cache($parsedkey); } } - if ($recurse && !empty($this->loader)) { + if ($recurse && $this->loader !== false) { // Delete from the bottom of the stack first. $this->loader->delete_many($keys, $recurse); } @@ -1572,11 +1572,13 @@ class cache_session extends cache { $new = 0; } if ($new !== self::$loadeduserid) { - // The current user doesn't match the tracker userid for this request. + // The current user doesn't match the tracked userid for this request. if (!is_null(self::$loadeduserid)) { // Purge the data we have for the old user. // This way we don't bloat the session. $this->purge(); + // Update the session id just in case! + $this->sessionid = session_id(); } self::$loadeduserid = $new; $this->currentuserid = $new; @@ -1584,6 +1586,8 @@ class cache_session extends cache { // The current user matches the loaded user but not the user last used by this cache. $this->purge(); $this->currentuserid = $new; + // Update the session id just in case! + $this->sessionid = session_id(); } } @@ -1863,11 +1867,11 @@ class cache_session extends cache { public function purge() { // 1. Purge the session object. $this->session = array(); - // 2. Purge the store. - $this->get_store()->purge(); - // 3. Optionally pruge any stacked loaders. + // 2. Delete the record for this users session from the store. + $this->get_store()->delete($this->sessionid); + // 3. Optionally purge any stacked loaders in the same way. if ($this->get_loader()) { - $this->get_loader()->purge(); + $this->get_loader()->delete($this->sessionid); } return true; } diff --git a/cache/tests/cache_test.php b/cache/tests/cache_test.php index bf489922e95..3a5f19f19b6 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -349,14 +349,14 @@ class cache_phpunit_tests extends advanced_testcase { $this->assertTrue(true); } try { - $cache->get_many(array('exception1', 'exception2'), MUST_EXUST); + $cache->get_many(array('exception1', 'exception2'), MUST_EXIST); $this->fail('Exception expected from cache::get_many using MUST_EXIST'); } catch (Exception $e) { $this->assertTrue(true); } $cache->set('test', 'test'); try { - $cache->get_many(array('test', 'exception'), MUST_EXUST); + $cache->get_many(array('test', 'exception'), MUST_EXIST); $this->fail('Exception expected from cache::get_many using MUST_EXIST'); } catch (Exception $e) { $this->assertTrue(true);