Reputation: 37
For Typo3 8 following approach worked:
$tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tce->clear_cacheCmd($pid);
Using this in Typo3 9 causes this error:
Call to a member function getTSConfig() on null
in E:\wwwroot_T9LTS\typo3\sysext\core\Classes\DataHandling\DataHandler.php line 8971
What is the best approach to clear cache for a page id in Typo3 9?
Update
got it to work using CacheManager:
$cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
$cacheManager->flushCachesInGroupByTags('pages', [ 'pageId_'.$pid ]);
Upvotes: 0
Views: 1499
Reputation: 2685
You probably run into problems using the DataHandler to clear the cache when not logged in to the backend. In Extbase context you may use:
$cacheManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Service\CacheService::class);
$cacheManager->clearPageCache([1,2,3]);
Upvotes: 2
Reputation: 3747
You will have to initialize the class by calling the start() method:
$tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tce->start([], []);
$tce->clear_cacheCmd($pid);
See the documentation for details.
Upvotes: 1