Skip to content

Commit

Permalink
MDL-38565 cache: tidy up pre-integration
Browse files Browse the repository at this point in the history
Conflicts:
	lib/db/upgrade.php
  • Loading branch information
Sam Hemelryk committed Apr 18, 2013
1 parent 1a038ed commit 6318a38
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cache/classes/definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public static function load($id, array $definition, $datasourceaggregate = null)
$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;
Expand Down
4 changes: 3 additions & 1 deletion cache/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,10 @@ public static function clean_old_session_data($output = false) {
}
$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);
Expand Down
18 changes: 11 additions & 7 deletions cache/classes/loaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ public function has_any(array $keys) {
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);
}
Expand All @@ -774,7 +774,7 @@ public function delete_many(array $keys, $recurse = true) {
$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);
}
Expand Down Expand Up @@ -1572,18 +1572,22 @@ protected function check_tracked_user() {
$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;
} else if ($new !== $this->currentuserid) {
// 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();
}
}

Expand Down Expand Up @@ -1863,11 +1867,11 @@ public function set_many(array $keyvaluearray) {
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;
}
Expand Down
4 changes: 2 additions & 2 deletions cache/tests/cache_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,14 @@ protected function run_on_cache(cache_loader $cache) {
$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);
Expand Down

0 comments on commit 6318a38

Please sign in to comment.