Database
extends AbstractAdapter
in package
Database cache adapter class
Tags
Table of Contents
Properties
- $clock : ClockInterface
- Clock used to resolve the current time
- $db : AbstractAdapter|null
- Database adapter
- $table : string
- Cache db table
- $ttl : int
- Global time-to-live
Methods
- __construct() : mixed
- Constructor
- clear() : Database
- Clear all stored values from cache
- decrementItem() : int
- Atomically decrement a counter in cache, creating it at $initial if it doesn't exist
- deleteItem() : Database
- Delete a value in cache
- destroy() : Database
- Destroy cache resource
- getDb() : AbstractAdapter
- Get the current cache db adapter.
- getItem() : mixed
- Get an item from cache
- getItemTtl() : int
- Get the time-to-live for an item in cache
- getTable() : string
- Get the current cache db table.
- 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() : Database
- Save an item to cache
- setDb() : Database
- Set the current cache db adapter.
- setTable() : Database
- Set the cache db table
- setTtl() : AbstractAdapter
- Set the global time-to-live for the cache adapter
- createTable() : void
- Create table in database
- findRow() : array<string|int, mixed>|null
- Fetch the raw stored row for an item id, or null if it doesn't exist
- isFresh() : bool
- Determine if a cache envelope (with 'start'/'ttl' keys) is still within its time-to-live
- resolvePlaceholders() : array<string|int, mixed>
- Resolve the driver-specific placeholder tokens for an ordered list of parameter names
Properties
$clock
Clock used to resolve the current time
protected
ClockInterface
$clock
$db
Database adapter
protected
AbstractAdapter|null
$db
= null
$table
Cache db table
protected
string
$table
= 'pop_cache'
$ttl
Global time-to-live
protected
int
$ttl
= 0
Methods
__construct()
Constructor
public
__construct(AbstractAdapter $db[, int $ttl = 0 ][, string $table = 'pop_cache' ][, ClockInterface $clock = new ClockSystemClock() ]) : mixed
Instantiate the DB writer object
The DB table requires the following fields at a minimum:
id INT
key VARCHAR
start INT
ttl INT
value TEXT, VARCHAR, etc.
Parameters
- $db : AbstractAdapter
- $ttl : int = 0
- $table : string = 'pop_cache'
- $clock : ClockInterface = new ClockSystemClock()
clear()
Clear all stored values from cache
public
clear() : Database
Return values
DatabasedecrementItem()
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() — Database 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) : Database
Parameters
- $id : string
Return values
Databasedestroy()
Destroy cache resource
public
destroy() : Database
Return values
DatabasegetDb()
Get the current cache db adapter.
public
getDb() : AbstractAdapter
Return values
AbstractAdaptergetItem()
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
intgetTable()
Get the current cache db table.
public
getTable() : string
Return values
stringgetTtl()
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() — Database 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 ]) : Database
Parameters
- $id : string
- $value : mixed
- $ttl : int|null = null
Return values
DatabasesetDb()
Set the current cache db adapter.
public
setDb(AbstractAdapter $db) : Database
Parameters
- $db : AbstractAdapter
Return values
DatabasesetTable()
Set the cache db table
public
setTable(string $table) : Database
Parameters
- $table : string
Return values
DatabasesetTtl()
Set the global time-to-live for the cache adapter
public
setTtl(int $ttl) : AbstractAdapter
Parameters
- $ttl : int
Return values
AbstractAdaptercreateTable()
Create table in database
protected
createTable() : void
findRow()
Fetch the raw stored row for an item id, or null if it doesn't exist
protected
findRow(string $id) : array<string|int, mixed>|null
Parameters
- $id : string
Return values
array<string|int, mixed>|nullisFresh()
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
boolresolvePlaceholders()
Resolve the driver-specific placeholder tokens for an ordered list of parameter names
protected
resolvePlaceholders(Sql $sql, array<string|int, mixed> $names) : array<string|int, mixed>
Parameters
- $sql : Sql
- $names : array<string|int, mixed>