Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
cache_loader_with_locking Interface Reference

Cache Loader supporting locking. More...

Inheritance diagram for cache_loader_with_locking:
cache_application cache_disabled

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.
 

Detailed Description

Cache Loader supporting locking.

This interface should be given to classes already implementing cache_loader that also wish to support locking. It outlines the required structure for utilising locking functionality when using a cache.

Can be implemented by any class already implementing the cache_loader interface.

Member Function Documentation

◆ acquire_lock()

cache_loader_with_locking::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.

Parameters
string | int$key
Return values
boolTrue if the lock could be acquired, false otherwise.

Implemented in cache_application, and cache_disabled.

◆ check_lock_state()

cache_loader_with_locking::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 cache_application, and cache_disabled.

◆ release_lock()

cache_loader_with_locking::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 cache_application, and cache_disabled.


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