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\.
-
interface
FrontendInterface -
- Fully qualified name
-
\TYPO3\CMS\ Core\ Cache\ Frontend\ Frontend Interface
Contract for a Cache (frontend)
-
public const
PATTERN_ENTRYIDENTIFIER -
'/^, type string[a- z A- Z0- 9_%\\-&] {1,250}$/' Pattern an entry identifier 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\ Backend Interface
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
- Returns
-
mixed
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
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
- Returns
-
mixed
flushByTags(string[] $tags)-
Removes all cache entries of this cache which are tagged by any of the specified tags.
- param $tags
-
List of tags
- Returns
-
mixed
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. TYPO3 signs each entry with an HMAC derived from the encryption key and validates the signature when reading the entry. If an entry has no valid signature (such as entries written by an older TYPO3 version) and contains serialized PHP objects, it is discarded and treated as a cache miss so the application can regenerate it with a valid signature. Unsigned entries that contain only scalar values or arrays are still deserialized safely.
Changed in version 13.4.31 / 14.3.3 Important: #108604 - Mitigate deserialization flaws
It is implemented in
\TYPO3\.
Tip
The variable frontend is the most frequently used frontend and handles the widest range of data types.
PHP frontend
This frontend is specialized for caching executable PHP files. It adds the
methods
require 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\.
A backend used with the PHP frontend must implement
\TYPO3\. The file
backend and the simple file backend currently fulfill this requirement.
In addition to the methods defined by
\TYPO3\, it provides:
requireOnce ($entry Identifier) - Loads PHP code from the cache and
require_it right away.once require(string $entry Identifier) - Loads PHP code from the cache and
requireit right away.()
Unlike require_, 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.
Note
The PHP caching frontend can only be used to cache PHP files. It does not work with strings, arrays or objects. It is not intended as a page content cache.