Review main Merged Breaking

97191[!!!][FEATURE] Flush caches without DataHandler

Benni Mack CR +2 V +2 Nightmare +2594 −560 updated 10/31/26, 07:49

Commit message

The cache flushing logic of DataHandler depended on a backend user and
was extended by the hooks "clearPageCacheEval" and "clearCachePostProc",
each called from two places with different parameters. Flushing the
caches of a record required a DataHandler.

The new service \TYPO3\CMS\Core\Cache\Flush\CacheFlusher flushes the
caches of records, pages, cache tags and cache commands:

* CacheFlushDemand describes what to flush
* CacheFlushingContext replaces the backend user with the workspace
  and the permissions to flush the "pages" group or all caches
* CacheFlushResult reports the flushed tags and groups, the records,
  and what was skipped and why
* resolve() tells what would be flushed without flushing anything

The service dispatches all events itself, so callers only describe
what to flush. Cache groups are flushed via the existing
CacheFlushEvent, like the "cache:flush" command does. To reach caches
configured without groups, CacheManager::getCacheGroups() now also
returns their default group "all".

The PSR-14 events BeforeRecordRelatedCachesAreFlushedEvent,
BeforeCacheFlushEvent and AfterCacheFlushedEvent replace the removed
hooks.

DataHandler and the clear cache actions of the backend use the new
service. EXT:frontend and EXT:indexed_search react to the new events.
EXT:redirects rebuilds its cache in DataHandler hooks once per changed
source host, including the previous one.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Daniel Windloff +1
    • Garvin Hicking +1
  • Verified V +2 Done
    • Benni Mack +2
    • Daniel Windloff +1
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 2

Files 43

Show 23 more files

Review log 2433

Show 68 earlier messages
  1. Benni Mack uploaded patch set 1 10/28/26, 10:09

  2. Benni Mack marked it work in progress 10/28/26, 10:10

  3. core-ci voted on patch set 1 V -1 10/28/26, 10:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112699

  4. Benni Mack uploaded patch set 2 V -1 10/28/26, 16:05

  5. core-ci voted on patch set 2 V -1 10/28/26, 16:16 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112738

  6. Daniel Windloff commented on patch set 2 10/30/26, 06:08

    ClearCacheController.php:81

    Flushing the cache via button should have the same effect as saving the same page record from my point of view. Atm only the cache for the page itsself would be removed. PagesTsConfig etc. would not be resolved. Therefore, I suggest using `CacheFlushRequest::forRecord('pages', $pageUid);` here.

    AfterCacheFlushedEvent.php:24

    `cache:flush`, `cache:flushtags` commands and `Flush cache` of the install tool don't trigger this event.

    BeforeRecordRelatedCachesAreFlushedEvent.php:50

    additionalPageIdsToClearCache

    CacheFlushPageResolver.php:43

    Avoid unnecessary wrapper methods

    CacheFlushPageResolver.php:59

    Why deleted restriction here?

    CacheFlushRequest.php:55

    forPageTagsPageByIds to clarify that no further processing is done.

    CacheFlusher.php:124

    Check for 0/null before adding

    CacheFlushingContext.php:26

    Currently not used in CLI

    DataHandler.php:8904

    deprecate method?

    DataHandler.php:8910

    Move to a new service as ClearCacheController does the same logging

    RemoveIndexedContentOfChangedPages.php:39

    Check first for isEnabled with early return for false.

    RemoveIndexedContentOfChangedPages.php:44

    Use `$this->administrationRepository->removeIndexedPageContent($record->pageId);` to remove the additional `for` loop

    FlushPageCachesOnTemplateChange.php:28

    Even if tstemplate is factory default, I would suggest moving this to core as it affects persistance in general.

    FlushPageCachesOnTemplateChange.php:34

    Is this assumption correct, that a sys_template may affect any page? I had assumed, that a `sys_template` record can only really affect its own pid and all the child pages of that pid.
  7. Garvin Hicking commented on patch set 2 10/30/26, 08:30

    CacheFlushRequest.php:24

    We should call this "CacheFlushhDemand" to not maybe confuse this with PSR request context?
  8. Benni Mack uploaded patch set 3 V -1 10/30/26, 10:15

  1. core-ci voted on patch set 3 V +1 10/30/26, 10:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112846

  2. Benni Mack commented on patch set 3 10/30/26, 10:34

    ClearCacheController.php:81 Reply

    I kept the existing behaviour on purpose: before this change, the button called clear_cacheCmd($uid), which only flushed the page itself. forRecord('pages', …) would also flush siblings, parent and the targets of TCEMAIN.clearCacheCmd, which is what saving does, and what #99843 complains about on large trees. This patch should be a refactoring without behaviour changes, so I'd rather do this in a follow-up if we agree the button should behave like saving. What do you think?

    AfterCacheFlushedEvent.php:24 Reply

    Right, the docblock was outdated. Fixed in PS3: the event is dispatched by CacheFlusher only. cache:flush keeps dispatching the existing CacheFlushEvent, which CacheFlusher now uses for group flushes too, so listeners of CacheFlushEvent see group flushes from the CLI and the backend alike.

    BeforeRecordRelatedCachesAreFlushedEvent.php:50 Reply

    These aren't additional page ids: the list already holds everything core resolved for the record (its page, siblings, parent, grandparent), and listeners can also remove entries via setPageIds(). That's why I kept pageIds, together with addPageId()/getPageIds(). OK for you?

    CacheFlushPageResolver.php:43 Reply

    Done

    CacheFlushPageResolver.php:59 Reply

    It was carried over from DataHandler::prepareCacheFlush(), but it isn't needed: the check is only whether the record is a workspace version. Removed in PS3; it now just reads t3ver_oid

    CacheFlushRequest.php:24 Reply

    Done, renamed to CacheFlushDemand
  3. Benni Mack commented on patch set 3 10/30/26, 10:36

    CacheFlushRequest.php:55 Reply

    Done

    CacheFlusher.php:124 Reply

    Done for null: when no page can be found for the record (the record doesn't exist), it's now skipped as InvalidRecord, with a test. 0 stays valid, because records on the root page, e.g. sys_redirect, need their tags flushed and the root TSconfig applied.

    CacheFlushingContext.php:26 Reply

    Docblock fixed. The default context is meant for code running without a backend user, such as scheduler tasks or custom commands.

    DataHandler.php:8904 Reply

    Agreed, but as a follow-up

    DataHandler.php:8910 Reply

    Done, the new internal CacheFlushLogger is used by DataHandler and ClearCacheController.

    RemoveIndexedContentOfChangedPages.php:39 Reply

    Done

    RemoveIndexedContentOfChangedPages.php:44 Reply

    Done

    FlushPageCachesOnTemplateChange.php:28 Reply

    Moved, but to EXT:frontend rather than core: the sys_template TCA lives in EXT:frontend, so the listener now sits next to the table it is about.

    FlushPageCachesOnTemplateChange.php:34 Reply

    Mostly its subtree, but other templates can include it via basedOn, so a change can affect pages in completely different trees. Flushing only the subtree would leave those stale, so it stays a flush of all page caches, as the old clearCachePostProc hook did. I added that to the docblock. Narrowing it down, e.g. by resolving basedOn users, could be a follow-up.
  4. Benni Mack marked it ready for review 10/30/26, 10:49

  5. Daniel Windloff commented on patch set 3 10/30/26, 13:05

    ClearCacheController.php:81 Reply

    Keeping the existing behavior is fine. I just came across the difference as I compare the actual generated cache tags to flush. I did not expect any difference here.

    BeforeRecordRelatedCachesAreFlushedEvent.php:50 Reply

    I wanted to express this distinction between the pid and the additional pids derived from it. While reading, I found the use of both `pageId` and `pageIds` find the two terms not very clearly distinguishable.
  6. Daniel Windloff voted on patch set 3 CR +1 V +1 10/30/26, 13:32

  7. Garvin Hicking uploaded patch set 4 CR +1 V +1 10/30/26, 14:23

  8. Garvin Hicking uploaded patch set 5 10/30/26, 14:35

  9. Garvin Hicking uploaded patch set 6 10/30/26, 14:35

  10. core-ci voted on patch set 4 V -1 10/30/26, 14:37 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112882

  11. Garvin Hicking commented on patch set 6 10/30/26, 14:37

    I've added a small ReST change. Found two issues for which I've added a failing test only for now, would like your feedback: 1. pid=0 records aren't flushed 2. "flush all caches" flushes twice, might create race conditions? "One thing worth noting" ;) - The docs say that `resolve()` is side-effect free, while in reality possible `BeforeXXX` events are recommended to perform changes. These would be performed in a `resolve()` call too, and then maybe already have executed changes. Not sure if that is worth pointing out though.
  12. core-ci voted on patch set 6 V -1 10/30/26, 14:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112884

  13. core-ci voted on patch set 5 V -1 10/30/26, 14:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112883

  14. Benni Mack uploaded patch set 7 V -1 10/30/26, 17:01

  15. Benni Mack commented on patch set 6 10/30/26, 17:01

    Reply

    Both issues were valid, and are now covered.
  16. core-ci voted on patch set 7 V -1 10/30/26, 17:13 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112895

  17. Benni Mack uploaded patch set 8 V -1 10/30/26, 17:58

  18. core-ci voted on patch set 8 V +1 10/30/26, 18:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112898

  19. Garvin Hicking voted on patch set 8 CR +1 V +1 10/30/26, 20:15

  20. Benni Mack uploaded patch set 9 CR +1 V +1 10/30/26, 21:30

  21. Garvin Hicking voted on patch set 9 CR +1 V +1 10/30/26, 21:34

  22. core-ci voted on patch set 9 V +1 10/30/26, 21:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112917

  23. Daniel Windloff voted on patch set 9 CR +1 V +1 10/31/26, 04:12

  24. Benni Mack voted on patch set 9 CR +2 V +2 10/31/26, 07:48

  25. Benni Mack merged patch set 10 10/31/26, 07:49