PHP Class Jamm\Memory\Shm\SHMObject

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

Protected Properties

Property Type Description
$id
$max_size
$mem_object ShmMem
$mutex MultiAccess
$readonly
$shm_data_id
$shm_data_key
$shmsize

Public Methods

Method Description
__construct ( string $ID = '', integer $size, integer $maxsize )
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 Delete key or array of keys from storage (from map)
del_by_tags ( array | string $tag ) : boolean Delete keys by tags
del_old ( ) : boolean Delete old (by ttl) variables from storage (map)
get_ID ( )
get_keys ( ) Return array of all stored keys
get_stat ( ) : array Returns statistic information
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 ) : boolean 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, integer &$ttl_left ) : mixed Read data from memory storage
save ( string $key, mixed $value, integer $ttl = 259200, string | array $tags = NULL ) : boolean Save variable in memory storage
select_fx ( callable $fx, boolean $get_array = false ) : mixed Select from storage via callback function
set_ID ( $ID )
sort_map ( array $a, array $b ) : integer Sort map by start value at map This function are public only for the function "usort", she should not be used in interface.
unlock_key ( KeyAutoUnlocker $auto_unlocker ) : boolean Unlock key, locked by method 'lock_key'

Protected Methods

Method Description
find_free_space ( array $map, integer $size ) : integer Find free space in map to store data
read_data ( integer | int[] $from, integer | int[] $to, array $keys = NULL ) : string | array Read data from storage directly
write_data ( string | array $data, integer | array $start ) : boolean Write data to storage directly

Method Details

__construct() public method

public __construct ( string $ID = '', integer $size, integer $maxsize )
$ID string path to existing file, __FILE__ usually, will define scope (like prefix).
$size integer initial size of the memory block in bites
$maxsize integer

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 key
$value mixed value
$ttl integer Time To Live in seconds (value will be added to the current time)
$tags array | string tag array of tags for this key
return boolean

del() public method

Delete key or array of keys from storage (from map)
public del ( string | array $key ) : boolean
$key string | array key or array of keys
return boolean

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 (map)
public del_old ( ) : boolean
return boolean

find_free_space() protected method

Find free space in map to store data
protected find_free_space ( array $map, integer $size ) : integer
$map array
$size integer
return integer

get_ID() public method

public get_ID ( )

get_keys() public method

Return array of all stored keys
public get_keys ( )

get_stat() public method

Returns statistic information
public get_stat ( ) : array
return array

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

Example: Process 1 reads key simultaneously with Process 2. Value of this key are too old, so Process 1 going to refresh it. Simultaneously with Process 2. But both of them trying to lock_key, and Process 1 only will refresh value of key (taking it from database, e.g.), and Process 2 can decide, what he want to do - use old value and not spent time to database, or something else.
public lock_key ( mixed $key, mixed &$auto_unlocker_variable ) : boolean
$key mixed
$auto_unlocker_variable mixed - pass empty, just declared variable
return boolean

read() public method

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

read_data() protected method

Read data from storage directly
protected read_data ( integer | int[] $from, integer | int[] $to, array $keys = NULL ) : string | array
$from integer | int[] (integer or array of integers)
$to integer | int[] (integer or array of integers)
$keys array
return string | array

save() public method

Save variable in memory storage
public save ( string $key, mixed $value, integer $ttl = 259200, string | array $tags = NULL ) : boolean
$key string key
$value mixed value
$ttl integer Time To Live in seconds (value will be added to the current time)
$tags string | array tag array of tags for this key
return boolean

select_fx() public method

Select from storage via callback function
public select_fx ( callable $fx, boolean $get_array = false ) : mixed
$fx callable ($value, $index)
$get_array boolean
return mixed

set_ID() public method

public set_ID ( $ID )

sort_map() public method

Sort map by start value at map This function are public only for the function "usort", she should not be used in interface.
public sort_map ( array $a, array $b ) : integer
$a array
$b array
return integer

unlock_key() public method

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

write_data() protected method

Write data to storage directly
protected write_data ( string | array $data, integer | array $start ) : boolean
$data string | array
$start integer | array
return boolean

Property Details

$id protected property

protected $id

$max_size protected property

protected $max_size

$mem_object protected property

protected ShmMem,Jamm\Memory\Shm $mem_object
return ShmMem

$mutex protected property

protected MultiAccess,Jamm\Memory\Shm $mutex
return MultiAccess

$readonly protected property

protected $readonly

$shm_data_id protected property

protected $shm_data_id

$shm_data_key protected property

protected $shm_data_key

$shmsize protected property

protected $shmsize