PdoAdapter
extends AbstractAdapter
in package
implements
PruneableInterface
Table of Contents
Interfaces
- PruneableInterface
- Interface extends psr-6 and psr-16 caches to allow for pruning (deletion) of all expired cache items.
Constants
- MAX_KEY_LENGTH = 255
Properties
- $conn : PDO
- $connectionOptions : array<string|int, mixed>
- $dataCol : string
- $driver : string
- $dsn : string
- $idCol : string
- $lifetimeCol : string
- $marshaller : MarshallerInterface
- $namespace : string
- $password : string|null
- $serverVersion : string
- $table : string
- $timeCol : string
- $username : string|null
Methods
- __construct() : mixed
- You can either pass an existing database connection as PDO instance or a DSN string that will be used to lazy-connect to the database when the cache is actually used.
- commit() : bool
- Persists any deferred cache items.
- createConnection() : mixed
- createSystemCache() : AdapterInterface
- Returns the best possible adapter that your runtime supports.
- createTable() : void
- Creates the table to store cache items which can be called once for setup.
- prune() : bool
- doClear() : bool
- doDelete() : bool
- doFetch() : iterable<string|int, mixed>
- doHave() : bool
- doSave() : array<string|int, mixed>|bool
- getConnection() : PDO
- getDriver() : string
- getServerVersion() : string
- isTableMissing() : bool
Constants
MAX_KEY_LENGTH
private
mixed
MAX_KEY_LENGTH
= 255
Properties
$conn
private
PDO
$conn
$connectionOptions
private
array<string|int, mixed>
$connectionOptions
= []
$dataCol
private
string
$dataCol
= 'item_data'
$driver
private
string
$driver
$dsn
private
string
$dsn
$idCol
private
string
$idCol
= 'item_id'
$lifetimeCol
private
string
$lifetimeCol
= 'item_lifetime'
$marshaller
private
MarshallerInterface
$marshaller
$namespace
private
string
$namespace
$password
private
string|null
$password
= null
$serverVersion
private
string
$serverVersion
$table
private
string
$table
= 'cache_items'
$timeCol
private
string
$timeCol
= 'item_time'
$username
private
string|null
$username
= null
Methods
__construct()
You can either pass an existing database connection as PDO instance or a DSN string that will be used to lazy-connect to the database when the cache is actually used.
public
__construct(PDO|string $connOrDsn[, string $namespace = '' ][, int $defaultLifetime = 0 ][, array<string|int, mixed> $options = [] ][, MarshallerInterface|null $marshaller = null ]) : mixed
List of available options:
- db_table: The name of the table [default: cache_items]
- db_id_col: The column where to store the cache id [default: item_id]
- db_data_col: The column where to store the cache data [default: item_data]
- db_lifetime_col: The column where to store the lifetime [default: item_lifetime]
- db_time_col: The column where to store the timestamp [default: item_time]
- db_username: The username when lazy-connect [default: '']
- db_password: The password when lazy-connect [default: '']
- db_connection_options: An array of driver-specific connection options [default: []]
Parameters
- $connOrDsn : PDO|string
- $namespace : string = ''
- $defaultLifetime : int = 0
- $options : array<string|int, mixed> = []
- $marshaller : MarshallerInterface|null = null
Tags
commit()
Persists any deferred cache items.
public
commit() : bool
Return values
bool —True if all not-yet-saved items were successfully saved or there were none. False otherwise.
createConnection()
public
static createConnection(string $dsn[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $dsn : string
- $options : array<string|int, mixed> = []
createSystemCache()
Returns the best possible adapter that your runtime supports.
public
static createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory[, LoggerInterface|null $logger = null ]) : AdapterInterface
Using ApcuAdapter makes system caches compatible with read-only filesystems.
Parameters
- $namespace : string
- $defaultLifetime : int
- $version : string
- $directory : string
- $logger : LoggerInterface|null = null
Return values
AdapterInterfacecreateTable()
Creates the table to store cache items which can be called once for setup.
public
createTable() : void
Cache ID are saved in a column of maximum length 255. Cache data is saved in a BLOB.
Tags
prune()
public
prune() : bool
Return values
booldoClear()
protected
doClear(string $namespace) : bool
Parameters
- $namespace : string
Return values
booldoDelete()
protected
doDelete(array<string|int, mixed> $ids) : bool
Parameters
- $ids : array<string|int, mixed>
Return values
booldoFetch()
protected
doFetch(array<string|int, mixed> $ids) : iterable<string|int, mixed>
Parameters
- $ids : array<string|int, mixed>
Return values
iterable<string|int, mixed>doHave()
protected
doHave(string $id) : bool
Parameters
- $id : string
Return values
booldoSave()
protected
doSave(array<string|int, mixed> $values, int $lifetime) : array<string|int, mixed>|bool
Parameters
- $values : array<string|int, mixed>
- $lifetime : int
Return values
array<string|int, mixed>|boolgetConnection()
private
getConnection() : PDO
Return values
PDOgetDriver()
private
getDriver() : string
Return values
stringgetServerVersion()
private
getServerVersion() : string
Return values
stringisTableMissing()
private
isTableMissing(PDOException $exception) : bool
Parameters
- $exception : PDOException