Frontend cache collector
New in version 13.3
This request attribute is a replacement for
Typo
and
Typo
which has been
deprecated with TYPO3 v13.3.
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.
.
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
$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->getLifetime();
Copied!
Example: Get all cache tags
$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->getCacheTags();
Copied!