File locking plugin.
More...
|
| __construct ($name, array $configuration=array()) |
| Initialises the cache lock instance.
|
|
| __destruct () |
| Cleans up the instance what it is no longer needed.
|
|
| check_state ($key, $ownerid) |
| Checks if the given key is locked.
|
|
| lock ($key, $ownerid, $block=false) |
| Acquire a lock.
|
|
| unlock ($key, $ownerid, $forceunlock=false) |
| Releases an acquired lock.
|
|
|
int | $blockattempts = 100 |
| The number of attempts to acquire a lock when blocking is required before throwing an exception.
|
|
string | $cachedir |
| The absolute directory in which lock files will be created and looked for.
|
|
array | $locks = array() |
| An array containing the locks that have been acquired but not released so far.
|
|
int null | $maxlife = null |
| The maximum life in seconds for a lock file.
|
|
string | $name |
| The name of the cache lock instance.
|
|
File locking plugin.
- Copyright
- 2012 Sam Hemelryk
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ __construct()
cachelock_file::__construct |
( |
| $name, |
|
|
array | $configuration = array() ) |
Initialises the cache lock instance.
- Parameters
-
string | $name | The name of the cache lock |
array | $configuration | |
Implements cache_lock_interface.
◆ __destruct()
cachelock_file::__destruct |
( |
| ) |
|
◆ check_state()
cachelock_file::check_state |
( |
| $key, |
|
|
| $ownerid ) |
Checks if the given key is locked.
- Parameters
-
string | $key | |
string | $ownerid | |
Implements cache_lock_interface.
◆ get_lock_file()
cachelock_file::get_lock_file |
( |
| $key | ) |
|
|
protected |
Gets the name to use for a lock file.
- Parameters
-
- Return values
-
◆ lock()
cachelock_file::lock |
( |
| $key, |
|
|
| $ownerid, |
|
|
| $block = false ) |
Acquire a lock.
If the lock can be acquired: This function will return true.
If the lock cannot be acquired the result of this method is determined by the block param: $block = true (default) The function will block any further execution unti the lock can be acquired. This involves the function attempting to acquire the lock and the sleeping for a period of time. This process will be repeated until the lock is required or until a limit is hit (100 by default) in which case a cache exception will be thrown. $block = false The function will return false immediately.
If a max life has been specified and the lock can not be acquired then the lock file will be checked against this time. In the case that the file exceeds that max time it will be forcefully deleted. Because this can obviously be a dangerous thing it is not used by default. If it is used it should be set high enough that we can be as sure as possible that the executing code has completed.
- Parameters
-
string | $key | The key that we want to lock |
string | $ownerid | A unique identifier for the owner of this lock. Not used by default. |
bool | $block | True if we want the program block further execution until the lock has been acquired. |
- Return values
-
- Exceptions
-
cache_exception | If block is set to true and more than 100 attempts have been made to acquire a lock. |
Implements cache_lock_interface.
◆ unlock()
cachelock_file::unlock |
( |
| $key, |
|
|
| $ownerid, |
|
|
| $forceunlock = false ) |
Releases an acquired lock.
For more details see cache_lock::unlock()
- Parameters
-
string | $key | |
string | $ownerid | A unique identifier for the owner of this lock. Not used by default. |
bool | $forceunlock | If set to true the lock will be removed if it exists regardless of whether or not we own it. |
- Return values
-
Implements cache_lock_interface.
◆ $locks
array cachelock_file::$locks = array() |
|
protected |
An array containing the locks that have been acquired but not released so far.
Array of key => lock file path
◆ $maxlife
int null cachelock_file::$maxlife = null |
|
protected |
The maximum life in seconds for a lock file.
By default null for none.
The documentation for this class was generated from the following file: