Memory
extends AbstractAdapter
in package
Memory adapter cache class
Tags
Table of Contents
Properties
- $clock : ClockInterface
- Clock used to resolve the current time
- $items : array<string|int, mixed>
- Cached items, keyed by sha1($id)
- $ttl : int
- Global time-to-live
Methods
- __construct() : mixed
- Constructor
- clear() : Memory
- Clear all stored values from cache
- decrementItem() : int
- Atomically decrement a counter in cache, creating it at $initial if it doesn't exist
- deleteItem() : Memory
- Delete a value in cache
- destroy() : Memory
- Destroy cache resource
- 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() : Memory
- Save an item to cache
- setTtl() : AbstractAdapter
- Set the global time-to-live for the cache adapter
- isFresh() : bool
- Determine if a cache envelope (with 'start'/'ttl' keys) is still within its time-to-live
Properties
$clock
Clock used to resolve the current time
protected
ClockInterface
$clock
$items
Cached items, keyed by sha1($id)
protected
array<string|int, mixed>
$items
= []
$ttl
Global time-to-live
protected
int
$ttl
= 0
Methods
__construct()
Constructor
public
__construct([int $ttl = 0 ][, ClockInterface $clock = new ClockSystemClock() ]) : mixed
Instantiate the cache adapter object
Parameters
- $ttl : int = 0
- $clock : ClockInterface = new ClockSystemClock()
clear()
Clear all stored values from cache
public
clear() : Memory
Return values
MemorydecrementItem()
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
Non-atomic read-modify-write through the same start/ttl/value envelope used by saveItem()/getItem() — Memory has no native atomic primitive, so a counter here is an ordinary cached integer, fully interoperable with getItem()/hasItem()/deleteItem().
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) : Memory
Parameters
- $id : string
Return values
Memorydestroy()
Destroy cache resource
public
destroy() : Memory
Return values
MemorygetItem()
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
Non-atomic read-modify-write through the same start/ttl/value envelope used by saveItem()/getItem() — Memory has no native atomic primitive, so a counter here is an ordinary cached integer, fully interoperable with getItem()/hasItem()/deleteItem().
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 ]) : Memory
Parameters
- $id : string
- $value : mixed
- $ttl : int|null = null
Return values
MemorysetTtl()
Set the global time-to-live for the cache adapter
public
setTtl(int $ttl) : AbstractAdapter
Parameters
- $ttl : int
Return values
AbstractAdapterisFresh()
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>