PHP Interface Jamm\Memory\IMemoryStorage

Show file Open project: jamm/memory Interface Usage Examples

Public Methods

Method Description
acquire_key ( string $key, &$auto_unlocker ) : boolean Try to lock key, and if key is already locked - wait, until key will be unlocked.
add ( string $key, mixed $value, integer $ttl = 259200, array | string $tags = NULL ) : boolean Add value to memory storage, only if this key does not exists (or false will be returned).
del ( string | array $key ) : boolean | array Delete key or array of keys from storage
del_by_tags ( array | string $tag ) : boolean Delete keys by tags
del_old ( ) : boolean Delete old (by ttl) variables from storage
getErrLog ( )
getLastErr ( ) : string
get_ID ( )
get_keys ( ) : array
get_stat ( ) : array
increment ( string $key, mixed $by_value = 1, integer $limit_keys_count, integer $ttl = 259200 ) : integer | string | array Increment value of the key
lock_key ( mixed $key, mixed &$auto_unlocker_variable ) Get exclusive mutex for key. Key will be still accessible to read and write, but another process can exclude dog-pile effect, if before updating the key he will try to get this mutex.
read ( string | array $key, mixed &$ttl_left ) : mixed Read data from memory storage
save ( string $key, mixed $value, integer $ttl = 259200, array | string $tags = NULL ) : boolean Save variable in memory storage
select_fx ( callable $fx, boolean $get_array = false ) : mixed Select from storage via callback function Only values of 'array' type will be selected
set_ID ( $ID )
set_errors_triggering ( $errors_triggering = true )
unlock_key ( KeyAutoUnlocker $auto_unlocker ) : boolean Unlock key, locked by method 'lock_key'

Method Details

acquire_key() public method

Time of waiting is defined in max_wait_unlock constant of MemoryObject class.
public acquire_key ( string $key, &$auto_unlocker ) : boolean
$key string
$auto_unlocker
return boolean

add() public method

Add value to memory storage, only if this key does not exists (or false will be returned).
public add ( string $key, mixed $value, integer $ttl = 259200, array | string $tags = NULL ) : boolean
$key string
$value mixed
$ttl integer
$tags array | string
return boolean

del() public method

Delete key or array of keys from storage
public del ( string | array $key ) : boolean | array
$key string | array - keys
return boolean | array - if array of keys was passed, on error will be returned array of not deleted keys, or 'true' on success.

del_by_tags() public method

Delete keys by tags
public del_by_tags ( array | string $tag ) : boolean
$tag array | string - tag or array of tags
return boolean

del_old() public method

Delete old (by ttl) variables from storage
public del_old ( ) : boolean
return boolean

getErrLog() public method

public getErrLog ( )

getLastErr() public method

public getLastErr ( ) : string
return string

get_ID() public method

public get_ID ( )

get_keys() public method

public get_keys ( ) : array
return array of all stored keys

get_stat() public method

public get_stat ( ) : array
return array

increment() public method

Increment value of the key
public increment ( string $key, mixed $by_value = 1, integer $limit_keys_count, integer $ttl = 259200 ) : integer | string | array
$key string
$by_value mixed if stored value is an array: if $by_value is a value in array, new element will be pushed to the end of array, if $by_value is a key=>value array, new key=>value pair will be added (or updated)
$limit_keys_count integer - maximum count of elements (used only if stored value is array)
$ttl integer - set time to live for key
return integer | string | array new value of key

lock_key() public method

Get exclusive mutex for key. Key will be still accessible to read and write, but another process can exclude dog-pile effect, if before updating the key he will try to get this mutex.
public lock_key ( mixed $key, mixed &$auto_unlocker_variable )
$key mixed
$auto_unlocker_variable mixed - pass empty, just declared variable

read() public method

Read data from memory storage
public read ( string | array $key, mixed &$ttl_left ) : mixed
$key string | array (string or array of string keys)
$ttl_left mixed = (ttl - time()) of key. Use to exclude dog-pile effect, with lock/unlock_key methods.
return mixed

save() public method

Save variable in memory storage
public save ( string $key, mixed $value, integer $ttl = 259200, array | string $tags = NULL ) : boolean
$key string - key
$value mixed - value
$ttl integer - time to live (store) in seconds
$tags array | string - array of tags for this key
return boolean

select_fx() public method

Select from storage via callback function Only values of 'array' type will be selected
public select_fx ( callable $fx, boolean $get_array = false ) : mixed
$fx callable ($value_array,$key)
$get_array boolean
return mixed

set_ID() public method

public set_ID ( $ID )

set_errors_triggering() public method

public set_errors_triggering ( $errors_triggering = true )

unlock_key() public method

Unlock key, locked by method 'lock_key'
public unlock_key ( KeyAutoUnlocker $auto_unlocker ) : boolean
$auto_unlocker KeyAutoUnlocker
return boolean