ApcuBackend extends AbstractBackend implements TaggableBackendInterface, TransientBackendInterface

FinalYes

A caching backend which stores cache entries by using APCu.

The APCu backend is not very good with tagging and scales O(2n) with the number of tags. Do not use this backend if the data to be cached has many tags!

This backend uses the following types of keys:

  • tag_xxx xxx is tag name, value is array of associated identifiers identifier. This is "forward" tag index. It is mainly used for obtaining content by tag (get identifier by tag -> get content by identifier)
  • ident_xxx xxx is identifier, value is array of associated tags. This is "reverse" tag index. It provides quick access for all tags associated with this identifier and used when removing the identifier

Each key is prepended with a prefix. The prefix makes sure keys from the different installations do not conflict. By default, prefix consists from two parts separated by underscore character and ends in yet another underscore character:

  • "TYPO3"
  • Hash of path to TYPO3 and user running TYPO3

Table of Contents

Interfaces

TaggableBackendInterface
A contract for a cache backend which supports tagging.
TransientBackendInterface
A contract for a cache backends which store variables in volatile memory and as such support receiving any variable type to store.

Properties

$cacheIdentifier  : string
$defaultLifetime  : int
Default lifetime of a cache entry in seconds

Methods

__construct()  : mixed
Constructs this backend
collectGarbage()  : void
Does garbage collection
findIdentifiersByTag()  : array<string|int, mixed>
Finds and returns all cache entry identifiers which are tagged by the specified tag
flush()  : void
Removes all cache entries of this cache.
flushByTag()  : void
Removes all cache entries of this cache which are tagged by the specified tag.
flushByTags()  : void
Removes all cache entries of this cache which are tagged by any of the specified tags.
get()  : mixed
Loads data from the cache.
has()  : bool
Checks if a cache entry with the specified identifier exists.
remove()  : bool
Removes all cache entries matching the specified identifier.
set()  : void
Saves data in the cache.
setCache()  : void
Sets a reference to the cache frontend which uses this backend
setDefaultLifetime()  : void
Sets the default lifetime for this cache backend

Properties

$cacheIdentifier

protected string $cacheIdentifier

$defaultLifetime

Default lifetime of a cache entry in seconds

protected int $defaultLifetime = 3600

Methods

__construct()

Constructs this backend

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

Configuration options - unused here

collectGarbage()

Does garbage collection

public collectGarbage() : void

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

flushByTag()

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

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

The tag the entries must have

flushByTags()

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

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

List of tags

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

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, mixed $data[, array<string|int, mixed> $tags = [] ][, int|null $lifetime = null ]) : void
Parameters
$entryIdentifier : string

An identifier for this specific cache entry

$data : mixed

The data to be stored. mixed is allowed due to TransientBackendInterface

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

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

$lifetime : int|null = null

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

setDefaultLifetime()

Sets the default lifetime for this cache backend

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

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

Internal

Misused for testing purposes.

Tags
todo:

Fix tests and protect or remove


        
On this page

Search results