Skip to content

Commit 71bd964

Browse files
authored
chore: use CacheDataCollector for adding cache tags in DataHandler chapter (#5274)
This API was introduced with TYPO3 v13.3 and is a successor of `TypoScriptFrontendController->addCacheTags()`. Related: TYPO3-Documentation/Changelog-To-Doc#1042 Releases: main, 13.4
1 parent 4c3c209 commit 71bd964

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Documentation/ApiOverview/DataHandler/Database/Index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,14 @@ custom ViewHelper):
624624
:language: php
625625
:caption: EXT:my_extension/Classes/Controller/SomeController.php
626626

627+
.. versionadded:: 13.3
628+
The :ref:`frontend.cache.collector <typo3-request-attribute-frontend-cache-collector>`
629+
request attribut has been introduced as a successor of the now deprecated
630+
:php:`TypoScriptFrontendController->addCacheTags()` method. Switch to
631+
another version of this page for an example in an older TYPO3 version. For
632+
compatibility with TYPO3 v12 and v13 use
633+
:php:`TypoScriptFrontendController->addCacheTags()`.
634+
627635
Hook for cache post-processing
628636
------------------------------
629637

Documentation/ApiOverview/DataHandler/Database/_SomeController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66

77
use MyVendor\MyExtension\Domain\Model\ExampleModel;
88
use Psr\Http\Message\ResponseInterface;
9+
use TYPO3\CMS\Core\Cache\CacheDataCollector;
10+
use TYPO3\CMS\Core\Cache\CacheTag;
911
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
10-
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
1112

1213
final class SomeController extends ActionController
1314
{
1415
public function showAction(ExampleModel $example): ResponseInterface
1516
{
1617
// ...
1718

18-
/** @var TypoScriptFrontendController $frontendController */
19-
$frontendController = $this->request->getAttribute('frontend.controller');
20-
$frontendController->addCacheTags([
21-
sprintf('tx_myextension_example_%d', $example->getUid()),
22-
]);
19+
/** @var CacheDataCollector $cacheDataCollector */
20+
$cacheDataCollector = $this->request->getAttribute('frontend.cache.collector');
21+
$cacheDataCollector->addCacheTags(
22+
new CacheTag(sprintf('tx_myextension_example_%d', $example->getUid())),
23+
);
2324

2425
// ...
2526
}

0 commit comments

Comments
 (0)