PHP Class Jamm\Memory\Shm\SingleMemory

Inheritance: extends Jamm\Memory\MemoryObject, implements Jamm\Memory\Shm\ISingleMemory
Show file Open project: jamm/memory

Protected Properties

Property Type Description
$mem
$sem Jamm\Memory\Shm\IMutex

Public Methods

Method Description
add ( string $key, mixed $value, integer $ttl = 2592000, string | array $tags = NULL ) : boolean | integer Add key to memory. If this key already exists - false will returned.
del ( string $key ) : boolean Delete key from memory
del_by_tags ( array | string $tags ) : boolean Delete keys by tags
del_old ( ) : boolean Delete old (by ttl) variables from storage
getSingleMemory ( )
get_keys ( ) Return array of all stored keys
increment ( string $key, mixed $by_value = 1, integer $limit_keys_count, integer $ttl = 259200 ) : integer | string | array Increment value of 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, &$ttl_left ) : mixed Read key value from memory
save ( string $key, mixed $value, integer $ttl = 2592000, string | array $tags = NULL ) : boolean | void
select_fx ( callable $fx, boolean $get_array = false ) : mixed Select from memory elements by function $fx
setMutex ( Jamm\Memory\Shm\IMutex $mutex )
unlock_key ( KeyAutoUnlocker $key_auto_unlocker ) : boolean Unlock key, locked by method 'lock_key'

Protected Methods

Method Description
get_key_ttl ( $key, &$mem )
readmemory ( )
refresh ( )

Method Details

add() public method

Excludes simultaneously adding keys to exclude race condition.
public add ( string $key, mixed $value, integer $ttl = 2592000, string | array $tags = NULL ) : boolean | integer
$key string
$value mixed
$ttl integer
$tags string | array
return boolean | integer

del() public method

Delete key from memory
public del ( string $key ) : boolean
$key string
return boolean

del_by_tags() public method

Delete keys by tags
public del_by_tags ( array | string $tags ) : boolean
$tags 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

getSingleMemory() public method

public getSingleMemory ( )

get_key_ttl() protected method

protected get_key_ttl ( $key, &$mem )

get_keys() public method

Return array of all stored keys
public get_keys ( )

increment() public method

Increment value of 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 array: if $by_value is value in array, new element will be pushed to the end of array, if $by_value is key=>value array, 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
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 key value from memory
public read ( string | array $key, &$ttl_left ) : mixed
$key string | array
$ttl_left
return mixed

readmemory() abstract protected method

abstract protected readmemory ( )

refresh() abstract protected method

abstract protected refresh ( )

save() public method

public save ( string $key, mixed $value, integer $ttl = 2592000, string | array $tags = NULL ) : boolean | void
$key string key
$value mixed value
$ttl integer time to live
$tags string | array
return boolean | void

select_fx() public method

Select from memory elements by function $fx
public select_fx ( callable $fx, boolean $get_array = false ) : mixed
$fx callable
$get_array boolean
return mixed

setMutex() public method

public setMutex ( Jamm\Memory\Shm\IMutex $mutex )
$mutex Jamm\Memory\Shm\IMutex

unlock_key() public method

Unlock key, locked by method 'lock_key'
public unlock_key ( KeyAutoUnlocker $key_auto_unlocker ) : boolean
$key_auto_unlocker Jamm\Memory\KeyAutoUnlocker
return boolean

Property Details

$mem protected property

protected $mem

$sem protected property

protected IMutex,Jamm\Memory\Shm $sem
return Jamm\Memory\Shm\IMutex