Typo3DatabaseBackend

class \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend

Extends
AbstractBackend
Implements
TaggableBackendInterface

A caching backend which stores cache entries in database tables

Table of Contents

Interfaces

TaggableBackendInterface
A contract for a cache backend which supports tagging.

Constants

DATETIME_EXPIRYTIME_UNLIMITED  : mixed = '9999-12-31T23:59:59+0000'
FAKED_UNLIMITED_EXPIRE  : int = 2145909600
UNLIMITED_LIFETIME  : mixed = 0

Properties

$cache  : FrontendInterface
Reference to the cache which uses this backend
$cacheIdentifier  : string
$cacheTable  : string
$compression  : bool
$compressionLevel  : int
$context  : string
The current application context
$defaultLifetime  : int
Default lifetime of a cache entry in seconds
$maximumLifetime  : int
$tagsTable  : string

Methods

__construct()  : mixed
Constructs this backend
collectGarbage()  : mixed
Does garbage collection
findIdentifiersByTag()  : array
Finds and returns all cache entries 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
Removes all entries tagged by any of the specified tags. Performs the SQL operation as a bulk query for better performance.
get()  : mixed
Loads data from a cache file.
getCacheTable()  : string
Returns the table where the cache entries are stored.
getTableDefinitions()  : string
Calculate needed table definitions for this cache.
getTagsTable()  : string
Gets the table where cache tags are stored.
has()  : bool
Checks if a cache entry with the specified identifier exists.
remove()  : bool
Removes all cache entries matching the specified identifier.
set()  : mixed
Saves data in a cache file.
setCache()  : mixed
Set cache frontend instance and calculate data and tags table name
setCompression()  : mixed
Enable data compression
setCompressionLevel()  : mixed
Set data compression level.
setDefaultLifetime()  : mixed
Sets the default lifetime for this cache backend
calculateExpiryTime()  : DateTime
Calculates the expiry time by the given lifetime. If no lifetime is specified, the default lifetime is used.
isConnectionMysql()  : bool
This database backend uses some optimized queries for mysql to get maximum performance.
throwExceptionIfFrontendDoesNotExist()  : mixed
Check if required frontend instance exists

Constants

DATETIME_EXPIRYTIME_UNLIMITED

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

FAKED_UNLIMITED_EXPIRE

public int FAKED_UNLIMITED_EXPIRE = 2145909600

Timestamp of 2038-01-01)

UNLIMITED_LIFETIME

public mixed UNLIMITED_LIFETIME = 0

Properties

$cacheIdentifier

protected string $cacheIdentifier

$cacheTable

protected string $cacheTable

Name of the cache data table

$compression

protected bool $compression = false

Indicates whether data is compressed or not (requires php zlib)

$compressionLevel

protected int $compressionLevel = -1

-1 to 9, indicates zlib compression level: -1 = default level 6, 0 = no compression, 9 maximum compression

$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.

$defaultLifetime

Default lifetime of a cache entry in seconds

protected int $defaultLifetime = 3600

$maximumLifetime

protected int $maximumLifetime

Maximum lifetime to stay with expire field below FAKED_UNLIMITED_LIFETIME

$tagsTable

protected string $tagsTable

Name of the cache tags table

Methods

__construct()

Constructs this backend

public __construct(string $context[, array $options = [] ]) : mixed

Parameters

$context : string

Unused, for backward compatibility only

$options : array = []

Configuration options - depends on the actual backend

Tags

throws
InvalidArgumentException

collectGarbage()

Does garbage collection

public collectGarbage() : mixed

findIdentifiersByTag()

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

public findIdentifiersByTag(string $tag) : array

Parameters

$tag : string

The tag to search for

Return values

array —

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()

Removes all entries tagged by any of the specified tags. Performs the SQL operation as a bulk query for better performance.

public flushByTags(string[] $tags) : mixed

Parameters

$tags : string[]

get()

Loads data from a cache file.

public get(string $entryIdentifier) : mixed

Parameters

$entryIdentifier : string

An identifier which describes the cache entry to load

Return values

mixed —

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

getCacheTable()

Returns the table where the cache entries are stored.

public getCacheTable() : string

Return values

string —

The cache table.

getTableDefinitions()

Calculate needed table definitions for this cache.

public getTableDefinitions() : string

This helper method is used by install tool and extension manager and is not part of the public API!

Return values

string —

SQL of table definitions

getTagsTable()

Gets the table where cache tags are stored.

public getTagsTable() : string

Return values

string —

Name of the table storing tags

has()

Checks if a cache entry with the specified identifier exists.

public has(string $entryIdentifier) : bool

Parameters

$entryIdentifier : string

Specifies the identifier to check for existence

Return values

bool —

TRUE if such an entry exists, FALSE if not

remove()

Removes all cache entries matching the specified identifier.

public remove(string $entryIdentifier) : bool

Usually this only affects one entry.

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 a cache file.

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

Parameters

$entryIdentifier : string

An identifier for this specific cache entry

$data : string

The data to be stored

$tags : array = []

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
InvalidDataException

if the data to be stored is not a string.

setCompression()

Enable data compression

public setCompression(bool $compression) : mixed

Parameters

$compression : bool

TRUE to enable compression

setCompressionLevel()

Set data compression level.

public setCompressionLevel(int $compressionLevel) : mixed

If compression is enabled and this is not set, gzcompress default level will be used

Parameters

$compressionLevel : int

-1 to 9: Compression level

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

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

isConnectionMysql()

This database backend uses some optimized queries for mysql to get maximum performance.

protected isConnectionMysql(Connection $connection) : bool

Parameters

$connection : Connection

Return values

bool

throwExceptionIfFrontendDoesNotExist()

Check if required frontend instance exists

protected throwExceptionIfFrontendDoesNotExist() : mixed

Tags

throws
Exception

If there is no frontend instance in $this->cache

On this page