Frontend cache collector

New in version 13.3

This request attribute is a replacement for TypoScriptFrontendController->addCacheTags() and TypoScriptFrontendController->getPageCacheTags() which has been deprecated with TYPO3 v13.3 and removed with TYPO3 v14.0.

An API is available to collect cache tags and their corresponding lifetime. This API is used in TYPO3 to accumulate cache tags from page cache and content object cache.

The API is implemented as a PSR-7 request attribute frontend.cache.collector.

Every cache tag has a lifetime. The minimum lifetime is calculated from all given cache tags. API users do not have to deal with it individually. The default lifetime for a cache tag is 86400 seconds (24 hours).

Example: Add a single cache tag

// use TYPO3\CMS\Core\Cache\CacheTag;

$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->addCacheTags(
    new CacheTag('tx_myextension_mytable'),
);
Copied!

Example: Add multiple cache tags with different lifetimes

// use TYPO3\CMS\Core\Cache\CacheTag;

$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->addCacheTags(
    new CacheTag('tx_myextension_mytable_123', 3600),
    new CacheTag('tx_myextension_mytable_456', 2592000),
);
Copied!

Example: Remove a single cache tag

// use TYPO3\CMS\Core\Cache\CacheTag;

$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->removeCacheTags(
    new CacheTag('tx_myextension_mytable_123'),
);
Copied!

Example: Remove multiple cache tags

// use TYPO3\CMS\Core\Cache\CacheTag;

$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->removeCacheTags(
    new CacheTag('tx_myextension_mytable_123'),
    new CacheTag('tx_myextension_mytable_456'),
);
Copied!

Example: Get minimum lifetime, calculated from all cache tags

Get minimum lifetime, calculated from all cache tags
$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->getLifetime();
Copied!

Example: Get all cache tags

$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->getCacheTags();
Copied!

API

class CacheDataCollector
Fully qualified name
\TYPO3\CMS\Core\Cache\CacheDataCollector
getCacheTags ( )
Returns
\CacheTag[]
addCacheTags ( \TYPO3\CMS\Core\Cache\CacheTag ...$cacheTags)
param $cacheTags

the cacheTags

removeCacheTags ( \TYPO3\CMS\Core\Cache\CacheTag ...$cacheTags)
param $cacheTags

the cacheTags

restrictMaximumLifetime ( int $lifetime)
param $lifetime

the lifetime

resolveLifetime ( )
Returns
int
enqueueCacheEntry ( \TYPO3\CMS\Core\Cache\CacheEntry $deferredCacheItem)
param $deferredCacheItem

the deferredCacheItem

getCacheEntries ( )
Returns
\CacheEntry[]