Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250620) (7d9030acd6e)
core_cache\loader_with_locking_interface Interface Reference
Inheritance diagram for core_cache\loader_with_locking_interface:
core_cache\application_cache core_cache\disabled_cache

Public Member Functions

 acquire_lock ($key)
 Acquires a lock for the given key.
 
 check_lock_state ($key)
 Checks if the cache loader owns the lock for the given key.
 
 release_lock ($key)
 Releases the lock for the given key.
 

Member Function Documentation

◆ acquire_lock()

core_cache\loader_with_locking_interface::acquire_lock ( $key)

Acquires a lock for the given key.

Please note that this happens automatically if the cache definition requires locking. it is still made a public method so that adhoc caches can use it if they choose. 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.

Parameters
string | int$key
Return values
boolAlways returns true (for backwards compatibility)
Exceptions
moodle_exceptionIf the lock cannot be obtained after a timeout

Implemented in core_cache\application_cache, and core_cache\disabled_cache.

◆ check_lock_state()

core_cache\loader_with_locking_interface::check_lock_state ( $key)

Checks if the cache loader owns the lock for the given key.

Please note that this happens automatically if the cache definition requires locking. it is still made a public method so that adhoc caches can use it if they choose. However this doesn't guarantee consistent access. It will become the responsibility of the calling code to ensure locks are acquired, checked, and released.

Parameters
string | int$key
Return values
boolTrue if this code has the lock, false if there is a lock but this code doesn't have it, null if there is no lock.

Implemented in core_cache\application_cache, and core_cache\disabled_cache.

◆ release_lock()

core_cache\loader_with_locking_interface::release_lock ( $key)

Releases the lock for the given key.

Please note that this happens automatically if the cache definition requires locking. it is still made a public method so that adhoc caches can use it if they choose. However this doesn't guarantee consistent access. It will become the responsibility of the calling code to ensure locks are acquired, checked, and released.

Parameters
string | int$key
Return values
boolTrue if the lock has been released, false if there was a problem releasing the lock.

Implemented in core_cache\application_cache, and core_cache\disabled_cache.


The documentation for this interface was generated from the following file: