PdoBackend extends AbstractBackend implements TaggableBackendInterface

A PDO database cache backend

Deprecated

since v11, will be removed in v12. Use Typo3DatabaseBackend instead. Drop Resources/Private/Sql/Cache/Backend/PdoBackendCacheAndTags.sql when class is dropped.

Table of Contents

Interfaces

TaggableBackendInterface
A contract for a cache backend which supports tagging.

Constants

DATETIME_EXPIRYTIME_UNLIMITED  = '9999-12-31T23:59:59+0000'
UNLIMITED_LIFETIME  = 0

Properties

$cache  : FrontendInterface
Reference to the cache which uses this backend
$cacheIdentifier  : string
$context  : string
The current application context
$databaseHandle  : PDO
$dataSourceName  : string
$defaultLifetime  : int
Default lifetime of a cache entry in seconds
$password  : string
$pdoDriver  : string
$username  : string

Methods

__construct()  : mixed
Constructs this backend
collectGarbage()  : mixed
Does garbage collection
findIdentifiersByTag()  : array<string|int, mixed>
Finds and returns all cache entry identifiers which are tagged by the specified tag.
flush()  : mixed
Removes all cache entries of this cache.
flushByTag()  : mixed
Removes all cache entries of this cache which are tagged by the specified tag.
flushByTags()  : mixed
Backwards compatibility safeguard since re-introducing flushByTags as API.
get()  : mixed
Loads data from the cache.
has()  : bool
Checks if a cache entry with the specified identifier exists.
initializeObject()  : mixed
Initialize the cache backend.
remove()  : bool
Removes all cache entries matching the specified identifier.
set()  : mixed
Saves data in the cache.
setCache()  : mixed
Sets a reference to the cache frontend which uses this backend
setDataSourceName()  : mixed
Sets the DSN to use
setDefaultLifetime()  : mixed
Sets the default lifetime for this cache backend
setPassword()  : mixed
Sets the password to use
setUsername()  : mixed
Sets the username to use
calculateExpiryTime()  : DateTime
Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.
connect()  : mixed
Connect to the database
createCacheTables()  : mixed
Creates the tables needed for the cache backend.
getNotExpiredStatement()  : string
Returns an SQL statement that evaluates to TRUE if the entry is not expired.
importSql()  : void
Pumps the SQL into the database. Use for DDL only.

Constants

DATETIME_EXPIRYTIME_UNLIMITED

public mixed DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000'

UNLIMITED_LIFETIME

public mixed UNLIMITED_LIFETIME = 0

Properties

$cacheIdentifier

protected string $cacheIdentifier

$context

The current application context

protected string $context

This variable is currently unused and set to "production" always. It is only kept to keep backwards compatibility.

$databaseHandle

protected PDO $databaseHandle

$dataSourceName

protected string $dataSourceName

$defaultLifetime

Default lifetime of a cache entry in seconds

protected int $defaultLifetime = 3600

Methods

__construct()

Constructs this backend

public __construct(mixed $context[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$context : mixed

Unused, for backward compatibility only

$options : array<string|int, mixed> = []

Configuration options - depends on the actual backend

collectGarbage()

Does garbage collection

public collectGarbage() : mixed

findIdentifiersByTag()

Finds and returns all cache entry identifiers which are tagged by the specified tag.

public findIdentifiersByTag(string $tag) : array<string|int, mixed>
Parameters
$tag : string

The tag to search for

Return values
array<string|int, mixed>

An array with identifiers of all matching entries. An empty array if no entries matched

flush()

Removes all cache entries of this cache.

public flush() : mixed

flushByTag()

Removes all cache entries of this cache which are tagged by the specified tag.

public flushByTag(string $tag) : mixed
Parameters
$tag : string

The tag the entries must have

flushByTags()

Backwards compatibility safeguard since re-introducing flushByTags as API.

public flushByTags(array<string|int, string> $tags) : mixed

See https://review.typo3.org/#/c/50537/ comments for patch set 14.

The method is here even though it is only required for TaggableBackendInterface. We add it here to ensure third party cache backends do not fail but instead delegate to a less efficient linear flushing behavior.

Parameters
$tags : array<string|int, string>

get()

Loads data from the cache.

public get(string $entryIdentifier) : mixed
Parameters
$entryIdentifier : string

An identifier which describes the cache entry to load

Return values
mixed

The cache entry's content as a string or FALSE if the cache entry could not be loaded

has()

Checks if a cache entry with the specified identifier exists.

public has(string $entryIdentifier) : bool
Parameters
$entryIdentifier : string

An identifier specifying the cache entry

Return values
bool

TRUE if such an entry exists, FALSE if not

initializeObject()

Initialize the cache backend.

public initializeObject() : mixed

remove()

Removes all cache entries matching the specified identifier.

public remove(string $entryIdentifier) : bool

Usually this only affects one entry but if - for what reason ever - old entries for the identifier still exist, they are removed as well.

Parameters
$entryIdentifier : string

Specifies the cache entry to remove

Return values
bool

TRUE if (at least) an entry could be removed or FALSE if no entry was found

set()

Saves data in the cache.

public set(string $entryIdentifier, string $data[, array<string|int, mixed> $tags = [] ][, int $lifetime = null ]) : mixed
Parameters
$entryIdentifier : string

An identifier for this specific cache entry

$data : string

The data to be stored

$tags : array<string|int, mixed> = []

Tags to associate with this cache entry

$lifetime : int = null

Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.

Tags
throws
Exception

if no cache frontend has been set.

throws
InvalidArgumentException

if the identifier is not valid

throws
InvalidDataException

if $data is not a string

setDataSourceName()

Sets the DSN to use

public setDataSourceName(string $DSN) : mixed
Parameters
$DSN : string

The DSN to use for connecting to the DB

setDefaultLifetime()

Sets the default lifetime for this cache backend

public setDefaultLifetime(int $defaultLifetime) : mixed
Parameters
$defaultLifetime : int

Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.

Tags
throws
InvalidArgumentException

setPassword()

Sets the password to use

public setPassword(string $password) : mixed
Parameters
$password : string

The password to use for connecting to the DB

setUsername()

Sets the username to use

public setUsername(string $username) : mixed
Parameters
$username : string

The username to use for connecting to the DB

calculateExpiryTime()

Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.

protected calculateExpiryTime([int $lifetime = null ]) : DateTime
Parameters
$lifetime : int = null

The lifetime in seconds

Return values
DateTime

The expiry time

connect()

Connect to the database

protected connect() : mixed
Tags
throws
RuntimeException

if something goes wrong

createCacheTables()

Creates the tables needed for the cache backend.

protected createCacheTables() : mixed
Tags
throws
RuntimeException

if something goes wrong

getNotExpiredStatement()

Returns an SQL statement that evaluates to TRUE if the entry is not expired.

protected getNotExpiredStatement() : string
Return values
string

importSql()

Pumps the SQL into the database. Use for DDL only.

protected importSql(PDO $databaseHandle, string $pdoDriver, string $pathAndFilename) : void

Important: key definitions with length specifiers (needed for MySQL) must be given as "field"(xyz) - no space between double quote and parenthesis - so they can be removed automatically.

Parameters
$databaseHandle : PDO
$pdoDriver : string
$pathAndFilename : string

        
On this page

Search results