Skip to content

Commit

Permalink
[TASK] v13 cache
Browse files Browse the repository at this point in the history
  • Loading branch information
achimfritz committed Sep 28, 2024
1 parent 96a884d commit 2f06d03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Classes/CacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Cache\CacheTag;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
Expand Down Expand Up @@ -86,7 +87,13 @@ protected function buildTagsAndAddThemToPageCache(array $pages): array
$tags = array_map(function ($pageId) {
return 'menuId_' . $pageId;
}, $usedPageIds);
$this->getFrontendController()->addCacheTags($tags);

if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
$this->getFrontendController()->addCacheTags($tags);
} else {
$cacheDataCollector = $this->getServerRequest()->getAttribute('frontend.cache.collector');
$cacheDataCollector->addCacheTags(...array_map(fn(string $tag) => new CacheTag($tag), $tags));
}
return $tags;
}

Expand Down
5 changes: 5 additions & 0 deletions Tests/Functional/DataProcessing/ListMenuProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use B13\Menus\DataProcessing\ListMenu;
use TYPO3\CMS\Core\Cache\CacheDataCollector;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Site\Entity\Site;
Expand Down Expand Up @@ -317,6 +318,8 @@ public function processTest(array $tsfe, array $configuration, array $expected)
$request = GeneralUtility::makeInstance(ServerRequest::class);
$request = $request->withAttribute('site', $site);
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
$cacheDataCollector = new CacheDataCollector();
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
$GLOBALS['TYPO3_REQUEST'] = $request;

$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
Expand Down Expand Up @@ -371,6 +374,8 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, array $configuration,
$request = GeneralUtility::makeInstance(ServerRequest::class);
$request = $request->withAttribute('site', $site);
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
$cacheDataCollector = new CacheDataCollector();
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
$GLOBALS['TYPO3_REQUEST'] = $request;

$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
Expand Down
5 changes: 5 additions & 0 deletions Tests/Functional/DataProcessing/TreeMenuProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

use B13\Menus\DataProcessing\TreeMenu;
use TYPO3\CMS\Core\Cache\CacheDataCollector;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Site\Entity\Site;
Expand Down Expand Up @@ -401,6 +402,8 @@ public function processTest(array $tsfe, array $configuration, array $expected):
$request = GeneralUtility::makeInstance(ServerRequest::class);
$request = $request->withAttribute('site', $site);
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
$cacheDataCollector = new CacheDataCollector();
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
$GLOBALS['TYPO3_REQUEST'] = $request;

$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
Expand Down Expand Up @@ -466,6 +469,8 @@ public function menuIdTagsAreAddedToPageCache(array $tsfe, int $entryPoints, arr
$request = GeneralUtility::makeInstance(ServerRequest::class);
$request = $request->withAttribute('site', $site);
$request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE);
$cacheDataCollector = new CacheDataCollector();
$request = $request->withAttribute('frontend.cache.collector', $cacheDataCollector);
$GLOBALS['TYPO3_REQUEST'] = $request;

$GLOBALS['TSFE'] = $this->getTypoScriptFrontendController($site, $tsfe['id']);
Expand Down

0 comments on commit 2f06d03

Please sign in to comment.