MDL-38565 cache: tidy up pre-integration

This commit is contained in:
Sam Hemelryk 2013-04-18 14:50:14 +12:00
parent 4da28110c0
commit 5cba0c4ba3
5 changed files with 19 additions and 13 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -366,14 +366,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);
@ -1305,4 +1305,4 @@ class cache_phpunit_tests extends advanced_testcase {
$this->assertTrue($cache->delete('a'));
$this->assertFalse($cache->has('a'));
}
}
}

View File

@ -2118,7 +2118,7 @@ function xmldb_main_upgrade($oldversion) {
}
if ($oldversion < 2013041900.00) {
require_once($CFG->dirroot.'/cache/locallib.php');
require_once($CFG->dirroot . '/cache/locallib.php');
// The features bin needs updating.
cache_config_writer::update_default_config_stores();
// Main savepoint reached.