---
title: "Feature: #102422 - Introduce CacheDataCollector Api"
manual: "TYPO3 Core Changelog"
version: "main"
permalink: "https://docs.typo3.org/permalink/changelog:feature-109999-1700506000"
source: "Changelog/13.3/Feature-102422-CacheDataCollectorApi.rst"
typo3-version: "13.3"
typo3-major: 13
type: "feature"
issue: 109999
forge: "https://forge.typo3.org/issues/109999"
tags: ["PHP-API", "ext:core"]
rendered: "2026-09-20T18:31:11+00:00"
---

# Feature: #102422 - Introduce CacheDataCollector Api {#feature-109999-1700506000}

See [forge#102422](https://forge.typo3.org/issues/102422)

## Description {#description}

A new API has been introduced 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 new PSR-7 request attribute
`'frontend.cache.collector'`, which makes this API independent from TSFE.

Every cache tag has a lifetime. The minimum lifetime is calculated
from all given cache tags. By default, the lifetime of a cache tag is set to
`PHP_INT_MAX`, so it expires many years in the future. API users must
therefore define the lifetime of a cache tag individually.

The current TSFE API is deprecated in favor of the new API, as the
current cache tag API implementation does not allow to set lifetime and
extension authors had to work around it.

### Example {#example}

**Add a single cache tag with 24 hours lifetime**

```php
use TYPO3\CMS\Core\Cache\CacheTag;

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

**Add multiple cache tags with different lifetimes**

```php
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)
);
```

**Remove a cache tag**

```php
use TYPO3\CMS\Core\Cache\CacheTag;

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

**Remove multiple cache tags**

```php
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')
);
```

**Get minimum lifetime, calculated from all cache tags**

```php
$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
$cacheDataCollector->resolveLifetime();
```

**Get all cache tags**

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

The following event should only be used in code that has no access to the
request attribute `'frontend.cache.collector'`, it is marked `@internal`
and may vanish: It designed to allow passive cache-data signaling, without
exactly knowing the current context and not having the current request at hand.
It is not meant to allow for cache tag interception or extension.

**Add cache tag without access to the request object**

```php
$this->eventDispatcher->dispatch(
    new AddCacheTagEvent(
        new CacheTag('tx_myextension_mytable_123', 3600)
    )
);
```
