Cache frontends 

A cache frontend is the public API for interacting with a cache. It defines which value types are accepted and how they are prepared for storage (for example serialization or compilation), while delegating persistence to the assigned backend. In everyday use, extensions should work with the frontend only — direct access to the caching backend is discouraged.

Caching frontend API 

All caching frontends must implement the interface \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface .

interface FrontendInterface
Fully qualified name
\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface

Contract for a Cache (frontend)

public const TAG_CLASS

'%CLASS%', type string

"Magic" tag for class-related entries

public const TAG_PACKAGE

'%PACKAGE%', type string

"Magic" tag for package-related entries

public const PATTERN_ENTRYIDENTIFIER

'/^[a-zA-Z0-9_%\\-&]{1,250}$/', type string

Pattern an entry identifier must match.

public const PATTERN_TAG

'/^[a-zA-Z0-9_%\\-&]{1,250}$/', type string

Pattern a tag must match.

getIdentifier ( )

Returns this cache's identifier

Return description

The identifier for this cache

Returns
string
getBackend ( )

Returns the backend used by this cache

Return description

The backend used by this cache

Returns
\TYPO3\CMS\Core\Cache\Backend\BackendInterface
set ( ?string $entryIdentifier, ?mixed $data, array $tags = [], ?int $lifetime = NULL)

Saves data in the cache.

param $entryIdentifier

Something which identifies the data - depends on concrete cache

param $data

The data to cache - also depends on the concrete cache implementation

param $tags

Tags to associate with this cache entry, default: []

param $lifetime

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

get ( ?string $entryIdentifier)

Finds and returns data from the cache.

param $entryIdentifier

Something which identifies the cache entry - depends on concrete cache

Returns
mixed
has ( ?string $entryIdentifier)

Checks if a cache entry with the specified identifier exists.

param $entryIdentifier

An identifier specifying the cache entry

Return description

TRUE if such an entry exists, FALSE if not

Returns
bool
remove ( ?string $entryIdentifier)

Removes the given cache entry from the cache.

param $entryIdentifier

An identifier specifying the cache entry

Return description

TRUE if such an entry exists, FALSE if not

Returns
bool
flush ( )

Removes all cache entries of this cache.

flushByTag ( ?string $tag)

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

param $tag

The tag the entries must have

flushByTags ( array $tags)

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

param $tags

List of tags

collectGarbage ( )

Does garbage collection

isValidEntryIdentifier ( ?string $identifier)

Checks the validity of an entry identifier. Returns TRUE if it's valid.

param $identifier

An identifier to be checked for validity

Returns
bool
isValidTag ( ?string $tag)

Checks the validity of a tag. Returns TRUE if it's valid.

param $tag

A tag to be checked for validity

Returns
bool

The specific cache frontend implementation migth offer additional methods.

Available cache frontend implementations 

Two frontends are currently available. They primarily differ in the data types they accept and how values are handled before they are passed to the backend.

Variable frontend 

This frontend accepts strings, arrays, and objects. Values are serialized before they are written to the caching backend.

It is implemented in \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend .

PHP frontend 

This frontend is specialized for caching executable PHP files. It adds the methods requireOnce() and require() to load a cached file directly. This is useful for extensions that generate PHP code at runtime, for example when heavy reflection or dynamic class construction is involved.

It is implemented in \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend .

A backend used with the PHP frontend must implement \TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface . The file backend and the simple file backend currently fulfill this requirement.

In addition to the methods defined by \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface , it provides:

requireOnce($entryIdentifier)
Loads PHP code from the cache and require_once it right away.
require(string $entryIdentifier)
Loads PHP code from the cache and require() it right away.

Unlike require_once(), require() is safe only when the cached code can be included multiple times within a single request. Files that declare classes, functions, or constants may trigger redeclaration errors.