Documentation

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

$connectionOptions

private array<string|int, mixed> $connectionOptions = []

$lifetimeCol

private string $lifetimeCol = 'item_lifetime'

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
throws
InvalidArgumentException

When first argument is not PDO nor Connection nor string

throws
InvalidArgumentException

When PDO error mode is not PDO::ERRMODE_EXCEPTION

throws
InvalidArgumentException

When namespace contains invalid characters

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
AdapterInterface

createTable()

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
throws
PDOException

When the table already exists

throws
DomainException

When an unsupported PDO driver is used

prune()

public prune() : bool
Return values
bool

doClear()

protected doClear(string $namespace) : bool
Parameters
$namespace : string
Return values
bool

doDelete()

protected doDelete(array<string|int, mixed> $ids) : bool
Parameters
$ids : array<string|int, mixed>
Return values
bool

doFetch()

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
bool

doSave()

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>|bool

getConnection()

private getConnection() : PDO
Return values
PDO

getDriver()

private getDriver() : string
Return values
string

getServerVersion()

private getServerVersion() : string
Return values
string

isTableMissing()

private isTableMissing(PDOException $exception) : bool
Parameters
$exception : PDOException
Return values
bool

        
On this page

Search results