class PdoBackend extends AbstractBackend implements TaggableBackendInterface, IterableBackendInterface, PhpCapableBackendInterface, WithSetupInterface, WithStatusInterface (View source)

A PDO database cache backend

Traits

RequireOnceFromValueTrait

Constants

DATETIME_EXPIRYTIME_UNLIMITED

UNLIMITED_LIFETIME

Properties

protected FrontendInterface $cache

Reference to the cache frontend which uses this backend

from  AbstractBackend
protected string $cacheIdentifier from  AbstractBackend
protected string $identifierPrefix

A prefix to seperate stored by appliaction context and cache

from  AbstractBackend
protected int $defaultLifetime

Default lifetime of a cache entry in seconds

from  AbstractBackend
protected EnvironmentConfiguration $environmentConfiguration from  AbstractBackend
protected array $_requiredEntryIdentifiers from  RequireOnceFromValueTrait
protected string $dataSourceName
protected string $username
protected string $password
protected array $driverOptions
protected PDO $databaseHandle
protected string $pdoDriver
protected string $context
protected string $cacheTableName
protected string $tagsTableName
protected int $batchSize
protected ArrayIterator|null $cacheEntriesIterator

Methods

__construct(EnvironmentConfiguration $environmentConfiguration = null, array $options = [])

Constructs this backend

void
setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)

No description

bool
setProperty(string $propertyName, mixed $propertyValue)

No description

void
setCache(FrontendInterface $cache)

Sets a reference to the cache frontend which uses this backend

void
setDefaultLifetime(int|string $defaultLifetime)

Sets the default lifetime for this cache backend

calculateExpiryTime(int $lifetime = null)

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

string
getPrefixedIdentifier(string $entryIdentifier)

Returns the internally used, prefixed entry identifier for the given public entry identifier.

mixed
requireOnce(string $entryIdentifier)

Loads PHP code from the cache and require_onces it right away.

void
setDataSourceName(string $DSN)

Sets the DSN to use

void
setUsername(string $username)

Sets the username to use

void
setPassword(string $password)

Sets the password to use

void
setDriverOptions(array $driverOptions)

Sets the driverOptions to use

void
setCacheTableName(string $cacheTableName)

Sets the name of the "cache" table

void
setTagsTableName(string $tagsTableName)

Sets the name of the "tags" table

void
setBatchSize(int $batchSize)

Sets the maximum number of items for batch operations

void
set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

Saves data in the cache.

mixed
get(string $entryIdentifier)

Loads data from the cache.

bool
has(string $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

bool
remove(string $entryIdentifier)

Removes all cache entries matching the specified identifier.

void
flush()

Removes all cache entries of this cache.

int
flushByTag(string $tag)

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

int
flushByTags(array $tags)

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

array
findIdentifiersByTag(string $tag)

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

void
collectGarbage()

Does garbage collection

string
getNotExpiredStatement()

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

void
connect()

Connect to the database

void
createCacheTables()

Creates the tables needed for the cache backend.

mixed
current()

Returns the data of the current cache entry pointed to by the cache entry iterator.

void
next()

Move forward to the next cache entry.

string
key()

Returns the identifier of the current cache entry pointed to by the cache entry iterator.

bool
valid()

Checks if the current position of the cache entry iterator is valid.

void
rewind()

Rewinds the cache entry iterator to the first element and fetches cacheEntries.

string
context()

No description

setup()

Connects to the configured PDO database and adds/updates table schema if required

getStatus()

Validates that configured database is accessible and schema up to date

Details

__construct(EnvironmentConfiguration $environmentConfiguration = null, array $options = [])

Constructs this backend

Parameters

EnvironmentConfiguration $environmentConfiguration
array $options

Configuration options - depends on the actual backend

protected void setProperties(array $properties, bool $throwExceptionIfPropertyNotSettable = true)

No description

Parameters

array $properties
bool $throwExceptionIfPropertyNotSettable

Return Value

void

Exceptions

InvalidArgumentException

protected bool setProperty(string $propertyName, mixed $propertyValue)

No description

Parameters

string $propertyName
mixed $propertyValue

Return Value

bool

void setCache(FrontendInterface $cache)

Sets a reference to the cache frontend which uses this backend

Parameters

FrontendInterface $cache

The frontend for this backend

Return Value

void

void setDefaultLifetime(int|string $defaultLifetime)

Sets the default lifetime for this cache backend

Parameters

int|string $defaultLifetime

Default lifetime of this cache backend in seconds. 0 means unlimited lifetime.

Return Value

void

Exceptions

InvalidArgumentException

protected DateTime calculateExpiryTime(int $lifetime = null)

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

Parameters

int $lifetime

The lifetime in seconds

Return Value

DateTime

The expiry time

string getPrefixedIdentifier(string $entryIdentifier)

Returns the internally used, prefixed entry identifier for the given public entry identifier.

While Flow applications will mostly refer to the simple entry identifier, it may be necessary to know the actual identifier used by the cache backend in order to share cache entries with other applications. This method allows for retrieving it.

Note that, in case of the AbstractBackend, this method is returns just the given entry identifier.

Parameters

string $entryIdentifier

Return Value

string

mixed requireOnce(string $entryIdentifier)

Loads PHP code from the cache and require_onces it right away.

Parameters

string $entryIdentifier

An identifier which describes the cache entry to load

Return Value

mixed

Potential return value from the include operation

protected void setDataSourceName(string $DSN)

Sets the DSN to use

Parameters

string $DSN

The DSN to use for connecting to the DB

Return Value

void

protected void setUsername(string $username)

Sets the username to use

Parameters

string $username

The username to use for connecting to the DB

Return Value

void

protected void setPassword(string $password)

Sets the password to use

Parameters

string $password

The password to use for connecting to the DB

Return Value

void

protected void setDriverOptions(array $driverOptions)

Sets the driverOptions to use

Parameters

array $driverOptions

The options to use for connecting to the DB

Return Value

void

protected void setCacheTableName(string $cacheTableName)

Sets the name of the "cache" table

Parameters

string $cacheTableName

Return Value

void

protected void setTagsTableName(string $tagsTableName)

Sets the name of the "tags" table

Parameters

string $tagsTableName

Return Value

void

protected void setBatchSize(int $batchSize)

Sets the maximum number of items for batch operations

Parameters

int $batchSize

Return Value

void

void set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null)

Saves data in the cache.

Parameters

string $entryIdentifier

An identifier for this specific cache entry

string $data

The data to be stored

array $tags

Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.

int $lifetime

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

Return Value

void

Exceptions

Exception
InvalidArgumentException
FilesException

mixed get(string $entryIdentifier)

Loads data from the cache.

Parameters

string $entryIdentifier

An identifier which describes the cache entry to load

Return Value

mixed

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

Exceptions

Exception

bool has(string $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

Parameters

string $entryIdentifier

An identifier specifying the cache entry

Return Value

bool

true if such an entry exists, false if not

Exceptions

Exception

bool remove(string $entryIdentifier)

Removes all cache entries matching the specified identifier.

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

string $entryIdentifier

Specifies the cache entry to remove

Return Value

bool

true if (at least) an entry could be removed or false if no entry was found

Exceptions

Exception

void flush()

Removes all cache entries of this cache.

Return Value

void

Exceptions

Exception

int flushByTag(string $tag)

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

Parameters

string $tag

The tag the entries must have

Return Value

int

The number of entries which have been affected by this flush

Exceptions

Exception

int flushByTags(array $tags)

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

Parameters

array $tags

The tags the entries must have

Return Value

int

The number of entries which have been affected by this flush

Exceptions

Exception

array findIdentifiersByTag(string $tag)

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

Parameters

string $tag

The tag to search for

Return Value

array

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

Exceptions

Exception

void collectGarbage()

Does garbage collection

Return Value

void

Exceptions

Exception

protected string getNotExpiredStatement()

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

Return Value

string

protected void connect()

Connect to the database

Return Value

void

Exceptions

Exception

protected void createCacheTables()

Creates the tables needed for the cache backend.

Return Value

void

Exceptions

Exception

mixed current()

Returns the data of the current cache entry pointed to by the cache entry iterator.

Return Value

mixed

void next()

Move forward to the next cache entry.

Return Value

void

string key()

Returns the identifier of the current cache entry pointed to by the cache entry iterator.

Return Value

string

bool valid()

Checks if the current position of the cache entry iterator is valid.

Return Value

bool

true if the current position is valid, otherwise false

void rewind()

Rewinds the cache entry iterator to the first element and fetches cacheEntries.

Return Value

void

protected string context()

No description

Return Value

string

Result setup()

Connects to the configured PDO database and adds/updates table schema if required

Return Value

Result

Result getStatus()

Validates that configured database is accessible and schema up to date

Return Value

Result