Feature: #111263 - Flush caches without DataHandler
See forge#111263
Description
The cache flushing logic of
\TYPO3\
has been extracted into the new service
\TYPO3\. It flushes the caches of
changed records, pages, cache tags and cache commands without a
Data or a backend user.
What to flush is described by a
\TYPO3\:
Cacheflushes the pages related to a record, following the Page TSconfig optionsFlush Demand:: for Record ('tt_ content', 12) TCEMAIN.,clear Cache_ disable TCEMAIN.,clear Cache_ page Sibling Children TCEMAIN.andclear Cache_ page Grand Parent TCEMAIN., exactly likeclear Cache Cmd Datadoes.Handler Cacheflushes the cache tags "pageId_1" and "pageId_2" only, without resolving related pages or Page TSconfig.Flush Demand:: for Page Tags By Page Ids (1, 2) Cacheflushes cache tags in the caches of the "pages" group.Flush Demand:: for Tags ('news') Cacheflushes them in the caches of another group, and the group "all" flushes them in all caches, including caches without a group.Flush Demand:: for Tags In Group ('system', 'news') withadds cache tags of a group to a demand. Cache tags of a group that does not exist are skipped.Tags In Group () Cacheaccepts the cache commands known fromFlush Demand:: for Command ('pages') TCEMAIN..clear Cache Cmd
On whose behalf caches are flushed is described by
\TYPO3\: the workspace and
whether flushing the "pages" group or all caches is permitted.
Cache derives the permissions from
User TSconfig
options. and
options.. The default context is unrestricted.
Cache returns a
\TYPO3\ with the flushed cache
tags per cache group, the flushed groups, the records, and what was skipped
and why.
Cache returns the cache tags of one
group, or of all groups if none is given.
Cache returns the same information without flushing
anything. It dispatches the two "Before" events described below as well, so
their listeners must only change what is flushed and leave any follow-up
work to
\TYPO3\.
use TYPO3\CMS\Core\Cache\Flush\CacheFlusher;
use TYPO3\CMS\Core\Cache\Flush\CacheFlushDemand;
final readonly class MyImportService
{
public function __construct(
private CacheFlusher $cacheFlusher,
) {}
public function import(int $newsUid): void
{
// ... write the record ...
$result = $this->cacheFlusher->flush(
CacheFlushDemand::forRecord('tx_news_domain_model_news', $newsUid)
);
}
}
All events are dispatched by the service itself, so callers only describe
what to flush. Cache groups are flushed by dispatching the existing
\TYPO3\, like the
cache: command does, so listeners of that event now also react
to group flushes triggered in the backend. The "Clear cache" actions of the
backend toolbar and page tree use the new service as well, and so do the
cache: command and the flushing of cache tags of files,
folders and file metadata by the automatic frontend cache tagging (feature
toggle
frontend.).
cache:
reports cache groups that do not exist instead of throwing an exception.
Three new PSR-14 events replace the removed hooks:
\TYPO3\CMS\ Core\ Cache\ Event\ Before Record Related Caches Are Flushed Event - Dispatched for every changed record with the pages, cache tags and cache
commands related to it, which listeners may change with
add,Page Id () add,Tag () hasand the setters.Tag () \TYPO3\CMS\ Core\ Cache\ Event\ Before Cache Flush Event - Dispatched once per flush with the complete
Cache, which listeners may change. Its tag methods take the cache group as an optional second argument, "pages" by default.Flush Plan \TYPO3\CMS\ Core\ Cache\ Event\ After Cache Flushed Event - Dispatched once after the caches were flushed, with the
Cache, for example to purge a reverse proxy by the flushed cache tags.Flush Result
Impact
Caches of records can be flushed with the same rules as in
Data from any place and
without a backend user, and every flush reports what it flushed.