MDL-67020 Cache: Release locks in cache_application::get_many()

This commit is contained in:
Mark Johnson 2022-08-11 08:50:25 +01:00
parent 9e7d9a0e9b
commit c06fc0648d

View File

@ -1809,10 +1809,11 @@ class cache_application extends cache implements cache_loader_with_locking {
* @throws coding_exception
*/
public function get_many(array $keys, $strictness = IGNORE_MISSING) {
$locks = [];
if ($this->requirelockingread) {
foreach ($keys as $id => $key) {
$lock =$this->acquire_lock($key);
if (!$lock) {
$locks[$key] = $this->acquire_lock($key);
if (!$locks[$key]) {
if ($strictness === MUST_EXIST) {
throw new coding_exception('Could not acquire read locks for all of the items being requested.');
} else {
@ -1823,7 +1824,13 @@ class cache_application extends cache implements cache_loader_with_locking {
}
}
return parent::get_many($keys, $strictness);
$result = parent::get_many($keys, $strictness);
if ($this->requirelockingread) {
foreach ($locks as $key => $lock) {
$this->release_lock($key);
}
}
return $result;
}
/**