PHP Class MatthiasMullie\Scrapbook\Scale\Shard

Pass the individual KeyValueStore objects that compose the cache server pool into this constructor how you want the data to be sharded. The cache data will be sharded over them according to the order they were in when they were passed into this constructor (so make sure to always keep the order the same) The sharding is spread evenly and all cache servers will roughly receive the same amount of cache keys. If some servers are bigger than others, you can offset this by adding the KeyValueStore object more than once. Data can even be sharded among different adapters: one server in the shard pool can be Redis while another can be Memcached. Not sure why you would even want that, but you could!
Author: Matthias Mullie ([email protected])
Inheritance: implements MatthiasMullie\Scrapbook\KeyValueStore
Show file Open project: matthiasmullie/scrapbook

Protected Properties

Property Type Description
$caches MatthiasMullie\Scrapbook\KeyValueStore[]

Public Methods

Method Description
__construct ( MatthiasMullie\Scrapbook\KeyValueStore $cache1, MatthiasMullie\Scrapbook\KeyValueStore $cache2 = null ) Overloadable with multiple KeyValueStore objects.
add ( $key, $value, $expire )
addCache ( MatthiasMullie\Scrapbook\KeyValueStore $cache )
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
getShard ( string $key ) : MatthiasMullie\Scrapbook\KeyValueStore Get the shard (KeyValueStore object) that corresponds to a particular cache key.
getShards ( array $keys ) : SplObjectStorage Get a [KeyValueStore => array of cache keys] map (SplObjectStorage) for multiple cache keys.

Method Details

__construct() public method

Overloadable with multiple KeyValueStore objects.
public __construct ( MatthiasMullie\Scrapbook\KeyValueStore $cache1, MatthiasMullie\Scrapbook\KeyValueStore $cache2 = null )
$cache1 MatthiasMullie\Scrapbook\KeyValueStore
$cache2 MatthiasMullie\Scrapbook\KeyValueStore

add() public method

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

addCache() public method

public addCache ( MatthiasMullie\Scrapbook\KeyValueStore $cache )
$cache MatthiasMullie\Scrapbook\KeyValueStore

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

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

getShard() protected method

Get the shard (KeyValueStore object) that corresponds to a particular cache key.
protected getShard ( string $key ) : MatthiasMullie\Scrapbook\KeyValueStore
$key string
return MatthiasMullie\Scrapbook\KeyValueStore

getShards() protected method

Get a [KeyValueStore => array of cache keys] map (SplObjectStorage) for multiple cache keys.
protected getShards ( array $keys ) : SplObjectStorage
$keys array
return SplObjectStorage

increment() public method

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

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

touch() public method

public touch ( $key, $expire )

Property Details

$caches protected property

protected KeyValueStore[],MatthiasMullie\Scrapbook $caches
return MatthiasMullie\Scrapbook\KeyValueStore[]