PHP Class MatthiasMullie\Scrapbook\Adapters\MemoryStore

This is mainly useful for testing purposes, where this class can let you test application logic against cache, without having to run a cache server.
Author: Matthias Mullie ([email protected])
Inheritance: implements MatthiasMullie\Scrapbook\KeyValueStore
Show file Open project: matthiasmullie/scrapbook

Protected Properties

Property Type Description
$items array
$limit integer
$size integer

Public Methods

Method Description
__construct ( integer | string $limit = null )
add ( $key, $value, $expire )
cas ( $token, $key, $value, $expire )
decrement ( $key, $offset = 1, $initial, $expire )
delete ( $key )
deleteMulti ( array $keys )
flush ( )
get ( $key, &$token = null )
getMulti ( array $keys, array &$tokens = null )
increment ( $key, $offset = 1, $initial, $expire )
replace ( $key, $value, $expire )
set ( $key, $value, $expire )
setMulti ( array $items, $expire )
touch ( $key, $expire )

Protected Methods

Method Description
doIncrement ( string $key, integer $offset, integer $initial, integer $expire ) : integer | boolean Shared between increment/decrement: both have mostly the same logic (decrement just increments a negative value), but need their validation split up (increment won't accept negative values).
evict ( ) Least recently used cache values will be evicted from cache should it fill up too much.
exists ( string $key ) : boolean Checks if a value exists in cache and is not yet expired.
lru ( $key ) This cache uses least recently used algorithm. This is to be called with the key to be marked as just used.
normalizeTime ( integer $time ) : integer Times can be: * relative (in seconds) to current time, within 30 days * absolute unix timestamp * 0, for infinity.
shorthandToBytes ( string | integer $shorthand ) : integer Understands shorthand byte values (as used in e.g. memory_limit ini setting) and converts them into bytes.

Method Details

__construct() public method

public __construct ( integer | string $limit = null )
$limit integer | string Memory limit in bytes (defaults to 10% of memory_limit)

add() public method

public add ( $key, $value, $expire )

cas() public method

public cas ( $token, $key, $value, $expire )

decrement() public method

public decrement ( $key, $offset = 1, $initial, $expire )

delete() public method

public delete ( $key )

deleteMulti() public method

public deleteMulti ( array $keys )
$keys array

doIncrement() protected method

Shared between increment/decrement: both have mostly the same logic (decrement just increments a negative value), but need their validation split up (increment won't accept negative values).
protected doIncrement ( string $key, integer $offset, integer $initial, integer $expire ) : integer | boolean
$key string
$offset integer
$initial integer
$expire integer
return integer | boolean

evict() protected method

Least recently used cache values will be evicted from cache should it fill up too much.
protected evict ( )

exists() protected method

Checks if a value exists in cache and is not yet expired.
protected exists ( string $key ) : boolean
$key string
return boolean

flush() public method

public flush ( )

get() public method

public get ( $key, &$token = null )

getMulti() public method

public getMulti ( array $keys, array &$tokens = null )
$keys array
$tokens array

increment() public method

public increment ( $key, $offset = 1, $initial, $expire )

lru() protected method

This cache uses least recently used algorithm. This is to be called with the key to be marked as just used.
protected lru ( $key )

normalizeTime() protected method

The first case (relative time) will be normalized into a fixed absolute timestamp.
protected normalizeTime ( integer $time ) : integer
$time integer
return integer

replace() public method

public replace ( $key, $value, $expire )

set() public method

public set ( $key, $value, $expire )

setMulti() public method

public setMulti ( array $items, $expire )
$items array

shorthandToBytes() protected method

Understands shorthand byte values (as used in e.g. memory_limit ini setting) and converts them into bytes.
See also: http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
protected shorthandToBytes ( string | integer $shorthand ) : integer
$shorthand string | integer Amount of bytes (int) or shorthand value (e.g. 512M)
return integer

touch() public method

public touch ( $key, $expire )

Property Details

$items protected property

protected array $items
return array

$limit protected property

protected int $limit
return integer

$size protected property

protected int $size
return integer