Skip to content
Browse files

Merge branch '41997-25' of git://github.com/samhemelryk/moodle into M…

…OODLE_25_STABLE
  • Loading branch information...
2 parents 3ee1a66 + 96f91e3 commit a348f55e3fc9ec429e30c06329a4c63958dae79a @stronk7 stronk7 committed Oct 1, 2013
Showing with 79 additions and 16 deletions.
  1. +1 −1 cache/classes/definition.php
  2. +6 −1 cache/classes/dummystore.php
  3. +72 −14 cache/tests/cache_test.php
View
2 cache/classes/definition.php
@@ -823,7 +823,7 @@ public function use_static_acceleration() {
// Request caches should never use static acceleration - it just doesn't make sense.
return false;
}
- return $this->staticacceleration || $this->mode === cache_store::MODE_SESSION;
+ return $this->staticacceleration;
}
/**
View
7 cache/classes/dummystore.php
@@ -113,7 +113,12 @@ public function initialise(cache_definition $definition) {
// store things in its static array.
// - If the definition is not using static acceleration then the cache loader won't try to store anything
// and we will need to store it here in order to make sure it is accessible.
- $this->persist = !$definition->use_static_acceleration();
+ if ($definition->get_mode() !== self::MODE_APPLICATION) {
+ // Neither the request cache nor the session cache provide static acceleration.
+ $this->persist = true;
+ } else {
+ $this->persist = !$definition->use_static_acceleration();
+ }
}
/**
View
86 cache/tests/cache_test.php
@@ -1058,28 +1058,63 @@ public function test_alt_cache_path() {
*/
public function test_disable_stores() {
$instance = cache_config_phpunittest::instance();
- $instance->phpunit_add_definition('phpunit/disabletest', array(
+ $instance->phpunit_add_definition('phpunit/disabletest1', array(
'mode' => cache_store::MODE_APPLICATION,
'component' => 'phpunit',
- 'area' => 'disabletest'
+ 'area' => 'disabletest1'
+ ));
+ $instance->phpunit_add_definition('phpunit/disabletest2', array(
+ 'mode' => cache_store::MODE_SESSION,
+ 'component' => 'phpunit',
+ 'area' => 'disabletest2'
+ ));
+ $instance->phpunit_add_definition('phpunit/disabletest3', array(
+ 'mode' => cache_store::MODE_REQUEST,
+ 'component' => 'phpunit',
+ 'area' => 'disabletest3'
));
- $cache = cache::make('phpunit', 'disabletest');
- $this->assertInstanceOf('cache_phpunit_application', $cache);
- $this->assertEquals('cachestore_file', $cache->phpunit_get_store_class());
- $this->assertFalse($cache->get('test'));
- $this->assertTrue($cache->set('test', 'test'));
- $this->assertEquals('test', $cache->get('test'));
+ $caches = array(
+ 'disabletest1' => cache::make('phpunit', 'disabletest1'),
+ 'disabletest2' => cache::make('phpunit', 'disabletest2'),
+ 'disabletest3' => cache::make('phpunit', 'disabletest3')
+ );
+
+ $this->assertInstanceOf('cache_phpunit_application', $caches['disabletest1']);
+ $this->assertInstanceOf('cache_phpunit_session', $caches['disabletest2']);
+ $this->assertInstanceOf('cache_phpunit_request', $caches['disabletest3']);
+
+ $this->assertEquals('cachestore_file', $caches['disabletest1']->phpunit_get_store_class());
+ $this->assertEquals('cachestore_session', $caches['disabletest2']->phpunit_get_store_class());
+ $this->assertEquals('cachestore_static', $caches['disabletest3']->phpunit_get_store_class());
+
+ foreach ($caches as $cache) {
+ $this->assertFalse($cache->get('test'));
+ $this->assertTrue($cache->set('test', 'test'));
+ $this->assertEquals('test', $cache->get('test'));
+ }
cache_factory::disable_stores();
- $cache = cache::make('phpunit', 'disabletest');
- $this->assertInstanceOf('cache_phpunit_application', $cache);
- $this->assertEquals('cachestore_dummy', $cache->phpunit_get_store_class());
+ $caches = array(
+ 'disabletest1' => cache::make('phpunit', 'disabletest1'),
+ 'disabletest2' => cache::make('phpunit', 'disabletest2'),
+ 'disabletest3' => cache::make('phpunit', 'disabletest3')
+ );
- $this->assertFalse($cache->get('test'));
- $this->assertTrue($cache->set('test', 'test'));
- $this->assertEquals('test', $cache->get('test'));
+ $this->assertInstanceOf('cache_phpunit_application', $caches['disabletest1']);
+ $this->assertInstanceOf('cache_phpunit_session', $caches['disabletest2']);
+ $this->assertInstanceOf('cache_phpunit_request', $caches['disabletest3']);
+
+ $this->assertEquals('cachestore_dummy', $caches['disabletest1']->phpunit_get_store_class());
+ $this->assertEquals('cachestore_dummy', $caches['disabletest2']->phpunit_get_store_class());
+ $this->assertEquals('cachestore_dummy', $caches['disabletest3']->phpunit_get_store_class());
+
+ foreach ($caches as $cache) {
+ $this->assertFalse($cache->get('test'));
+ $this->assertTrue($cache->set('test', 'test'));
+ $this->assertEquals('test', $cache->get('test'));
+ }
}
/**
@@ -1108,6 +1143,7 @@ public function test_disable() {
$cache = cache::make('phpunit', 'disable');
$this->assertInstanceOf('cache_disabled', $cache);
+ // Test an application cache.
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'disable');
$this->assertInstanceOf('cache_disabled', $cache);
@@ -1118,6 +1154,28 @@ public function test_disable() {
$this->assertFalse($cache->delete('test'));
$this->assertTrue($cache->purge());
+ // Test a session cache.
+ $cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'disable');
+ $this->assertInstanceOf('cache_disabled', $cache);
+
+ $this->assertFalse(file_exists($configfile));
+
+ $this->assertFalse($cache->get('test'));
+ $this->assertFalse($cache->set('test', 'test'));
+ $this->assertFalse($cache->delete('test'));
+ $this->assertTrue($cache->purge());
+
+ // Finally test a request cache.
+ $cache = cache::make_from_params(cache_store::MODE_REQUEST, 'phpunit', 'disable');
+ $this->assertInstanceOf('cache_disabled', $cache);
+
+ $this->assertFalse(file_exists($configfile));
+
+ $this->assertFalse($cache->get('test'));
+ $this->assertFalse($cache->set('test', 'test'));
+ $this->assertFalse($cache->delete('test'));
+ $this->assertTrue($cache->purge());
+
cache_factory::reset();
$factory = cache_factory::instance(true);

0 comments on commit a348f55

Please sign in to comment.
Something went wrong with that request. Please try again.