PHP Class MatthiasMullie\Scrapbook\Adapters\Apc

Author: Matthias Mullie ([email protected])
Inheritance: implements MatthiasMullie\Scrapbook\KeyValueStore
Afficher le fichier Open project: matthiasmullie/scrapbook

Protected Properties

Свойство Type Description
$expires array APC does this crazy thing of only deleting expired data on every new (page) request, not checking it when you actually retrieve the value (which you may just have set in the same request) Since it's totally possible to store values that expire in the same request, we'll keep track of those expiration times here & filter them out in case they did expire.

Méthodes publiques

Méthode Description
__construct ( )
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 )

Méthodes protégées

Méthode Description
APCuIterator ( string | string[] | null $search = null, integer $format = null, integer $chunk_size = null, integer $list = null ) : APCIterato\APCIterator | APCuIterato\APCuIterator
acquire ( string | string[] $keys ) : string[] Acquire a lock - required to provide CAS functionality.
apcu_add ( string | string[] $key, mixed $var, integer $ttl ) : boolean | bool[]
apcu_clear_cache ( ) : boolean
apcu_delete ( string | string[] | APCIterato\APCIterator | APCuIterato\APCuIterator $key ) : boolean | string[]
apcu_fetch ( string | string[] $key, boolean &$success = null ) : mixed | false
apcu_store ( string | string[] $key, mixed $var, integer $ttl ) : boolean | bool[]
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).
expire ( array | string $key = [], integer $ttl ) Store the expiration time for items we're setting in this request, to work around APC's behavior of only clearing expires per page request.
lock ( string | string[] $keys ) : array Acquire a lock. If we failed to acquire a lock, it'll automatically try again in 1ms, for a maximum of 10 times.
ttl ( integer $expire ) : integer APC expects true TTL, not expiration timestamp.
unlock ( string | string[] $keys ) : boolean Release a lock.

Method Details

APCuIterator() protected méthode

protected APCuIterator ( string | string[] | null $search = null, integer $format = null, integer $chunk_size = null, integer $list = null ) : APCIterato\APCIterator | APCuIterato\APCuIterator
$search string | string[] | null
$format integer
$chunk_size integer
$list integer
Résultat APCIterato\APCIterator | APCuIterato\APCuIterator

__construct() public méthode

public __construct ( )

acquire() protected méthode

Acquire a lock - required to provide CAS functionality.
protected acquire ( string | string[] $keys ) : string[]
$keys string | string[]
Résultat string[] Array of successfully locked keys

add() public méthode

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

apcu_add() protected méthode

protected apcu_add ( string | string[] $key, mixed $var, integer $ttl ) : boolean | bool[]
$key string | string[]
$var mixed
$ttl integer
Résultat boolean | bool[]

apcu_clear_cache() protected méthode

protected apcu_clear_cache ( ) : boolean
Résultat boolean

apcu_delete() protected méthode

protected apcu_delete ( string | string[] | APCIterato\APCIterator | APCuIterato\APCuIterator $key ) : boolean | string[]
$key string | string[] | APCIterato\APCIterator | APCuIterato\APCuIterator
Résultat boolean | string[]

apcu_fetch() protected méthode

protected apcu_fetch ( string | string[] $key, boolean &$success = null ) : mixed | false
$key string | string[]
$success boolean
Résultat mixed | false

apcu_store() protected méthode

protected apcu_store ( string | string[] $key, mixed $var, integer $ttl ) : boolean | bool[]
$key string | string[]
$var mixed
$ttl integer
Résultat boolean | bool[]

cas() public méthode

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

decrement() public méthode

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

delete() public méthode

public delete ( $key )

deleteMulti() public méthode

public deleteMulti ( array $keys )
$keys array

doIncrement() protected méthode

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
Résultat integer | boolean

expire() protected méthode

Store the expiration time for items we're setting in this request, to work around APC's behavior of only clearing expires per page request.
See also: static::$expires
protected expire ( array | string $key = [], integer $ttl )
$key array | string
$ttl integer

flush() public méthode

public flush ( )

get() public méthode

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

getMulti() public méthode

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

increment() public méthode

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

lock() protected méthode

APC provides nothing that would allow us to do CAS. To "emulate" CAS, we'll work with locks: all cache writes also briefly create a lock cache entry (yup: #writes * 3, for lock & unlock - luckily, they're not over the network) Writes are disallows when a lock can't be obtained (= locked by another write), which makes it possible for us to first retrieve, compare & then set in a nob-atomic way. However, there's a possibility for interference with direct APC access touching the same keys - e.g. other scripts, not using this class. If CAS is of importance, make sure the only things touching APC on your server is using these classes!
protected lock ( string | string[] $keys ) : array
$keys string | string[]
Résultat array Array of successfully locked keys

replace() public méthode

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

set() public méthode

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

setMulti() public méthode

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

touch() public méthode

public touch ( $key, $expire )

ttl() protected méthode

APC expects true TTL, not expiration timestamp.
protected ttl ( integer $expire ) : integer
$expire integer
Résultat integer TTL in seconds

unlock() protected méthode

Release a lock.
protected unlock ( string | string[] $keys ) : boolean
$keys string | string[]
Résultat boolean

Property Details

$expires protected_oe property

APC does this crazy thing of only deleting expired data on every new (page) request, not checking it when you actually retrieve the value (which you may just have set in the same request) Since it's totally possible to store values that expire in the same request, we'll keep track of those expiration times here & filter them out in case they did expire.
See also: http://stackoverflow.com/questions/11750223/apc-user-cache-entries-not-expiring
protected array $expires
Résultat array