Apc
extends AbstractAdapter
in package
uses
NamespacedVersionedKeys
APC cache adapter class
Tags
Table of Contents
Properties
- $clock : ClockInterface
- Clock used to resolve the current time
- $namespace : string
- Cache namespace
- $ttl : int
- Global time-to-live
Methods
- __construct() : mixed
- Constructor
- clear() : Apc
- Clear all stored values from cache
- decrementItem() : int
- Atomically decrement a counter in cache, creating it at $initial if it doesn't exist
- deleteItem() : Apc
- Delete a value in cache
- destroy() : Apc
- Destroy cache resource
- getInfo() : array<string|int, mixed>
- Method to get the current APC info.
- getItem() : mixed
- Get an item from cache
- getItemTtl() : int
- Get the time-to-live for an item in cache
- getTtl() : int
- Get the global time-to-live for the cache object
- hasItem() : bool
- Determine if the item exist in cache
- incrementItem() : int
- Atomically increment a counter in cache, creating it at $initial if it doesn't exist
- saveItem() : Apc
- Save an item to cache
- setTtl() : AbstractAdapter
- Set the global time-to-live for the cache adapter
- fetchVersion() : mixed
- Fetch the raw version value from APCu, or false if it isn't set
- isFresh() : bool
- Determine if a cache envelope (with 'start'/'ttl' keys) is still within its time-to-live
- key() : string
- Build the versioned, namespaced storage key for an item id
- resolveVersion() : int
- Resolve the current version for this namespace, defaulting to 1
- versionKey() : string
- Get the storage key for this namespace's version counter
Properties
$clock
Clock used to resolve the current time
protected
ClockInterface
$clock
$namespace
Cache namespace
protected
string
$namespace
= 'pop_cache'
$ttl
Global time-to-live
protected
int
$ttl
= 0
Methods
__construct()
Constructor
public
__construct([int $ttl = 0 ][, string $namespace = 'pop_cache' ][, ClockInterface $clock = new ClockSystemClock() ]) : mixed
Instantiate the APC cache object
Parameters
- $ttl : int = 0
- $namespace : string = 'pop_cache'
- $clock : ClockInterface = new ClockSystemClock()
Tags
clear()
Clear all stored values from cache
public
clear() : Apc
Return values
ApcdecrementItem()
Atomically decrement a counter in cache, creating it at $initial if it doesn't exist
public
decrementItem(string $id[, int $amount = 1 ][, int $initial = 0 ][, int|null $ttl = null ]) : int
Stored as a raw scalar via apcu_add()/apcu_dec(), bypassing the start/ttl/value envelope used by saveItem()/getItem() entirely — a counter key and a saveItem()-managed key are two incompatible storage formats on this adapter, and a counter is not readable via getItem(). See incrementItem() for the apcu_add()+apcu_dec() atomicity rationale. Unlike Memcached::decrement(), APCu allows the result to go negative.
Parameters
- $id : string
- $amount : int = 1
- $initial : int = 0
- $ttl : int|null = null
Tags
Return values
intdeleteItem()
Delete a value in cache
public
deleteItem(string $id) : Apc
Parameters
- $id : string
Return values
Apcdestroy()
Destroy cache resource
public
destroy() : Apc
Return values
ApcgetInfo()
Method to get the current APC info.
public
getInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>getItem()
Get an item from cache
public
getItem(string $id[, mixed $default = false ]) : mixed
Parameters
- $id : string
- $default : mixed = false
getItemTtl()
Get the time-to-live for an item in cache
public
getItemTtl(string $id[, int $default = 0 ]) : int
Parameters
- $id : string
- $default : int = 0
Return values
intgetTtl()
Get the global time-to-live for the cache object
public
getTtl() : int
Return values
inthasItem()
Determine if the item exist in cache
public
hasItem(string $id) : bool
Parameters
- $id : string
Return values
boolincrementItem()
Atomically increment a counter in cache, creating it at $initial if it doesn't exist
public
incrementItem(string $id[, int $amount = 1 ][, int $initial = 0 ][, int|null $ttl = null ]) : int
Stored as a raw scalar via apcu_add()/apcu_inc(), bypassing the start/ttl/value envelope used by saveItem()/getItem() entirely — a counter key and a saveItem()-managed key are two incompatible storage formats on this adapter, and a counter is not readable via getItem(). apcu_inc() has no initial-value parameter of its own, so apcu_add() atomically seeds the key at $initial (only the caller that finds the key missing succeeds) before apcu_inc() unconditionally applies $amount — this two-call sequence stays race-free under concurrency. $ttl is honored only when the counter is first created by apcu_add(); a later call does not refresh an existing counter's expiry.
Parameters
- $id : string
- $amount : int = 1
- $initial : int = 0
- $ttl : int|null = null
Tags
Return values
intsaveItem()
Save an item to cache
public
saveItem(string $id, mixed $value[, int|null $ttl = null ]) : Apc
Parameters
- $id : string
- $value : mixed
- $ttl : int|null = null
Return values
ApcsetTtl()
Set the global time-to-live for the cache adapter
public
setTtl(int $ttl) : AbstractAdapter
Parameters
- $ttl : int
Return values
AbstractAdapterfetchVersion()
Fetch the raw version value from APCu, or false if it isn't set
protected
fetchVersion(string $key) : mixed
Parameters
- $key : string
isFresh()
Determine if a cache envelope (with 'start'/'ttl' keys) is still within its time-to-live
protected
isFresh(array<string|int, mixed> $envelope) : bool
Parameters
- $envelope : array<string|int, mixed>
Return values
boolkey()
Build the versioned, namespaced storage key for an item id
protected
key(string $id) : string
Parameters
- $id : string
Return values
stringresolveVersion()
Resolve the current version for this namespace, defaulting to 1
protected
resolveVersion() : int
Return values
intversionKey()
Get the storage key for this namespace's version counter
protected
versionKey() : string