MDL-41106 cache: several fixes for the session cache.
This issue makes several fixes for the session loader and the session store. * maxsize argument now works for session caches. * fixed performance hole when interation occurs frequently. * fixed cache purge bug occuring when multiple caches are defined before being used. * improved lastaccess handling. Big thanks to Marina who contributed the following commits: * Always make sure the elements in cache are sorted so we need to remove only elements in the beginning of array * Remove expired elements from session store to free memory * Minor bug fixes
This commit is contained in:
Vendored
+89
-2
@@ -1109,9 +1109,9 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that multiple loaders work ok.
|
||||
* Test that multiple application loaders work ok.
|
||||
*/
|
||||
public function test_multiple_loaders() {
|
||||
public function test_multiple_application_loaders() {
|
||||
$instance = cache_config_phpunittest::instance(true);
|
||||
$instance->phpunit_add_file_store('phpunittest1');
|
||||
$instance->phpunit_add_file_store('phpunittest2');
|
||||
@@ -1156,6 +1156,93 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$this->assertFalse($result['a']);
|
||||
$this->assertEquals('B', $result['b']);
|
||||
$this->assertFalse($result['c']);
|
||||
|
||||
// Test non-recursive deletes.
|
||||
$this->assertTrue($cache->set('test', 'test'));
|
||||
$this->assertSame('test', $cache->get('test'));
|
||||
$this->assertTrue($cache->delete('test', false));
|
||||
// We should still have it on a deeper loader.
|
||||
$this->assertSame('test', $cache->get('test'));
|
||||
// Test non-recusive with many functions.
|
||||
$this->assertSame(3, $cache->set_many(array(
|
||||
'one' => 'one',
|
||||
'two' => 'two',
|
||||
'three' => 'three'
|
||||
)));
|
||||
$this->assertSame('one', $cache->get('one'));
|
||||
$this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
|
||||
$this->assertSame(3, $cache->delete_many(array('one', 'two', 'three'), false));
|
||||
$this->assertSame('one', $cache->get('one'));
|
||||
$this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that multiple application loaders work ok.
|
||||
*/
|
||||
public function test_multiple_session_loaders() {
|
||||
/* @var cache_config_phpunittest $instance */
|
||||
$instance = cache_config_phpunittest::instance(true);
|
||||
$instance->phpunit_add_session_store('phpunittest1');
|
||||
$instance->phpunit_add_session_store('phpunittest2');
|
||||
$instance->phpunit_add_definition('phpunit/multi_loader', array(
|
||||
'mode' => cache_store::MODE_SESSION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'multi_loader'
|
||||
));
|
||||
$instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest1', 3);
|
||||
$instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest2', 2);
|
||||
|
||||
$cache = cache::make('phpunit', 'multi_loader');
|
||||
$this->assertInstanceOf('cache_session', $cache);
|
||||
$this->assertFalse($cache->get('test'));
|
||||
$this->assertTrue($cache->set('test', 'test'));
|
||||
$this->assertEquals('test', $cache->get('test'));
|
||||
$this->assertTrue($cache->delete('test'));
|
||||
$this->assertFalse($cache->get('test'));
|
||||
$this->assertTrue($cache->set('test', 'test'));
|
||||
$this->assertTrue($cache->purge());
|
||||
$this->assertFalse($cache->get('test'));
|
||||
|
||||
// Test the many commands.
|
||||
$this->assertEquals(3, $cache->set_many(array('a' => 'A', 'b' => 'B', 'c' => 'C')));
|
||||
$result = $cache->get_many(array('a', 'b', 'c'));
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertArrayHasKey('a', $result);
|
||||
$this->assertArrayHasKey('b', $result);
|
||||
$this->assertArrayHasKey('c', $result);
|
||||
$this->assertEquals('A', $result['a']);
|
||||
$this->assertEquals('B', $result['b']);
|
||||
$this->assertEquals('C', $result['c']);
|
||||
$this->assertEquals($result, $cache->get_many(array('a', 'b', 'c')));
|
||||
$this->assertEquals(2, $cache->delete_many(array('a', 'c')));
|
||||
$result = $cache->get_many(array('a', 'b', 'c'));
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertArrayHasKey('a', $result);
|
||||
$this->assertArrayHasKey('b', $result);
|
||||
$this->assertArrayHasKey('c', $result);
|
||||
$this->assertFalse($result['a']);
|
||||
$this->assertEquals('B', $result['b']);
|
||||
$this->assertFalse($result['c']);
|
||||
|
||||
// Test non-recursive deletes.
|
||||
$this->assertTrue($cache->set('test', 'test'));
|
||||
$this->assertSame('test', $cache->get('test'));
|
||||
$this->assertTrue($cache->delete('test', false));
|
||||
// We should still have it on a deeper loader.
|
||||
$this->assertSame('test', $cache->get('test'));
|
||||
// Test non-recusive with many functions.
|
||||
$this->assertSame(3, $cache->set_many(array(
|
||||
'one' => 'one',
|
||||
'two' => 'two',
|
||||
'three' => 'three'
|
||||
)));
|
||||
$this->assertSame('one', $cache->get('one'));
|
||||
$this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
|
||||
$this->assertSame(3, $cache->delete_many(array('one', 'two', 'three'), false));
|
||||
$this->assertSame('one', $cache->get('one'));
|
||||
$this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user