How to flush or update cache for page by id in TYPO3
Asked Answered
G

4

5

I need to flush a cache for a specific page from TYPO3 version 8 backend in the Extension from my Controller. I found a solution for flushing all caches but this is the last option.

Grisby answered 21/11, 2018 at 21:23 Comment(0)
S
14

GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class) ->flushCachesInGroupByTags('pages', [ 'pageId_'.$id ]);

Sapphira answered 21/11, 2018 at 22:13 Comment(0)
O
3

The core handles the page cache clear using the DataHandler;

See: \TYPO3\CMS\Recordlist\RecordList::clearCache

/**
 * Clears page cache for the given page id, $this->id
 */
public function clearCache(int $pageId)
{
    $tce = GeneralUtility::makeInstance(DataHandler::class);
    $tce->start([], []);
    $tce->clear_cacheCmd($pageId);
}
Offprint answered 22/11, 2018 at 8:1 Comment(2)
Thanks, I will try too. What is the difference between this two solutions?Wallraff
The other solution uses the internal logic from the DataHandler (tag naming scheme). The DataHandler internally uses the CacheManager too.Faultless
B
3

From within controller context (as asked..)

$this->cacheService->clearPageCache([$pageIds]);

This call includes the marked answer above.

Burier answered 6/5, 2019 at 7:53 Comment(0)
A
0

Sorry i cannot comment directly to the answer from Benjamin. The second solution with DataHandler only works in backend context. If you want to clear the cache from your frontend plugin, you must use the marked answer.

Attention answered 21/2, 2019 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.