mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-76745 cache: Implement cache_loader_with_locking in cache_disabled
If a plugin attempts to do something that would lock coursemodinfo cache during install (such as creating a course module), this currently fails as check_lock_state is not implemented in cache_disabled. Adding the cache_loader_with_locking interface ensures that all lock methods are implemented.
This commit is contained in:
parent
4ed782dd03
commit
09cf1b8818
22
cache/disabledlib.php
vendored
22
cache/disabledlib.php
vendored
@ -39,7 +39,7 @@ require_once($CFG->dirroot.'/cache/locallib.php');
|
|||||||
* @copyright 2012 Sam Hemelryk
|
* @copyright 2012 Sam Hemelryk
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class cache_disabled extends cache {
|
class cache_disabled extends cache implements cache_loader_with_locking {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the cache.
|
* Constructs the cache.
|
||||||
@ -204,20 +204,30 @@ class cache_disabled extends cache {
|
|||||||
/**
|
/**
|
||||||
* Pretend that we got a lock to avoid errors.
|
* Pretend that we got a lock to avoid errors.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param int|string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function acquire_lock(string $key) : bool {
|
public function acquire_lock($key) : bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pretend that we released a lock to avoid errors.
|
* Pretend that we released a lock to avoid errors.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param int|string $key
|
||||||
* @return void
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function release_lock(string $key) : bool {
|
public function release_lock($key) : bool {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pretend that we have a lock to avoid errors.
|
||||||
|
*
|
||||||
|
* @param int|string $key
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function check_lock_state($key) : bool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
cache/tests/cache_test.php
vendored
9
cache/tests/cache_test.php
vendored
@ -1426,6 +1426,15 @@ class cache_test extends \advanced_testcase {
|
|||||||
$this->assertFalse($cache->set_versioned('v', 1, 'data'));
|
$this->assertFalse($cache->set_versioned('v', 1, 'data'));
|
||||||
$this->assertFalse($cache->delete('test'));
|
$this->assertFalse($cache->delete('test'));
|
||||||
$this->assertTrue($cache->purge());
|
$this->assertTrue($cache->purge());
|
||||||
|
// Checking a lock should always report that we have one.
|
||||||
|
// Acquiring or releasing a lock should always report success.
|
||||||
|
$this->assertTrue($cache->check_lock_state('test'));
|
||||||
|
$this->assertTrue($cache->acquire_lock('test'));
|
||||||
|
$this->assertTrue($cache->acquire_lock('test'));
|
||||||
|
$this->assertTrue($cache->check_lock_state('test'));
|
||||||
|
$this->assertTrue($cache->release_lock('test'));
|
||||||
|
$this->assertTrue($cache->release_lock('test'));
|
||||||
|
$this->assertTrue($cache->check_lock_state('test'));
|
||||||
|
|
||||||
// Test a session cache.
|
// Test a session cache.
|
||||||
$cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'disable');
|
$cache = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'disable');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user