Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
cache_lock_interface Interface Reference

Cache lock interface. More...

Inheritance diagram for cache_lock_interface:
cachelock_file

Public Member Functions

 __construct ($name, array $configuration=array())
 Constructs an instance of the cache lock given its name and its configuration data.
 
 __destruct ()
 Cleans up any left over locks.
 
 check_state ($key, $ownerid)
 Checks the state of the given key.
 
 lock ($key, $ownerid, $block=false)
 Acquires a lock on a given key.
 
 unlock ($key, $ownerid, $forceunlock=false)
 Releases the lock held on a certain key.
 

Detailed Description

Cache lock interface.

This interface needs to be inherited by all cache lock plugins.

Constructor & Destructor Documentation

◆ __construct()

cache_lock_interface::__construct ( $name,
array $configuration = array() )

Constructs an instance of the cache lock given its name and its configuration data.

Parameters
string$nameThe unique name of the lock instance
array$configuration

Implemented in cachelock_file.

◆ __destruct()

cache_lock_interface::__destruct ( )

Cleans up any left over locks.

This function MUST clean up any locks that have been acquired and not released during processing. Although the situation of acquiring a lock and not releasing it should be insanely rare we need to deal with it. Things such as unfortunate timeouts etc could cause this situation.

Implemented in cachelock_file.

Member Function Documentation

◆ check_state()

cache_lock_interface::check_state ( $key,
$ownerid )

Checks the state of the given key.

Returns true if the key is locked and belongs to the ownerid. Returns false if the key is locked but does not belong to the ownerid. Returns null if there is no lock

Parameters
string$keyThe key we are checking for.
string$owneridThe identifier so we can check if we have the lock or if it is someone else.
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 cachelock_file.

◆ lock()

cache_lock_interface::lock ( $key,
$ownerid,
$block = false )

Acquires a lock on a given key.

Parameters
string$keyThe key to acquire a lock for.
string$owneridAn unique identifier for the owner of this lock. It is entirely optional for the cache lock plugin to use this. Each implementation can decide for themselves.
bool$blockIf set to true the application will wait until a lock can be acquired
Return values
boolTrue if the lock can be acquired false otherwise.

Implemented in cachelock_file.

◆ unlock()

cache_lock_interface::unlock ( $key,
$ownerid,
$forceunlock = false )

Releases the lock held on a certain key.

Parameters
string$keyThe key to release the lock for.
string$owneridAn unique identifier for the owner of this lock. It is entirely optional for the cache lock plugin to use this. Each implementation can decide for themselves.
bool$forceunlockIf set to true the lock will be removed if it exists regardless of whether or not we own it.

Implemented in cachelock_file.


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