MDL-78467 core_cache: Improve cache locking API

* Makes it possible to safely call acquire_lock so that it throws an
  exception instead of returning false if it can't get a lock (which
  most existing uses assumed it already does).
* Fix some omissions from the requirelockingbeforewrite option (it
  now checks on delete).
* Modinfo uses a versioned cache, so it is not necessary to delete
  items, only increase the version. (Provided we keep track of
  cacherev carefully...)
This commit is contained in:
sam marshall
2023-09-14 09:28:10 +01:00
parent 9b2c445143
commit 0f8577784d
9 changed files with 448 additions and 94 deletions
+5 -1
View File
@@ -248,8 +248,12 @@ interface cache_loader_with_locking {
* However this doesn't guarantee consistent access. It will become the responsibility of the calling code to ensure
* locks are acquired, checked, and released.
*
* Prior to Moodle 4,3 this function used to return false if the lock cannot be obtained. It
* now always returns true, and throws an exception if the lock cannot be obtained.
*
* @param string|int $key
* @return bool True if the lock could be acquired, false otherwise.
* @return bool Always returns true (for backwards compatibility)
* @throws moodle_exception If the lock cannot be obtained after a timeout
*/
public function acquire_lock($key);