#107159Regression: Replacing a file via Filelist no longer clears page cache in TYPO3 9+ (was working in 8.7)
Description
## Summary
In TYPO3 8.7, when replacing a file via the Filelist module using the “Replace” button, the page cache of records referencing that file was automatically cleared. This behavior no longer occurs in TYPO3 9, 10, or later versions.
## Expected behavior
Pages linking to the replaced file (e.g., a PDF in a `tt_content` media field) should have their cache invalidated after the file is replaced.
## Actual behavior
File is replaced correctly in the Filelist, but no page cache is invalidated. Pages continue to show/download the old file version (especially problematic with CDNs or browser caching).
## TYPO3 Version
13.x (also affects 10–12)
## Proposal
- Restore the automatic cache clearing behavior when a file is replaced,
## Notes
This change seems to be the result of the shift to PSR-14 event architecture and the removal of automatic calls to `clear_cacheCmd()` in the file handling process.
## Solution with eventListener
use TYPO3\CMS\Core\Resource\Event\AfterFileReplaceEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Backend\Utility\BackendUtility;
class InvalidateCacheOnFileReplace
{
public function __invoke(AfterFileReplaceEvent $event): void
{
$file = $event->getFile();
$fileRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\FileRepository::class);
$references = $fileRepository->findByFile($file);
$pageIdsToClear = [];
foreach ($references as $reference) {
$table = $reference->getTablenames();
$uid = $reference->getUid();
$record = BackendUtility::getRecord($table, $reference->getUidForeign(), 'pid');
if ($record && isset($record['pid'])) {
$pageIdsToClear[] = (int)$record['pid'];
}
}
$pageIdsToClear = array_unique($pageIdsToClear);
if (!empty($pageIdsToClear)) {
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start([], []);
$dataHandler->clear_cacheCmd(implode(',', $pageIdsToClear));
}
}
}Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.