83012[BUGFIX] Always respect default cache group 'all'
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 1
Review log 1112
-
Robert Kärner uploaded patch set 1 02/15/24, 11:43
-
core-ci voted on patch set 1 V +1 02/15/24, 11:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53227
-
Georg Ringer voted on patch set 1 CR +1 V +1 03/11/24, 20:52
-
Jörg Bösche voted on patch set 1 CR +1 03/25/24, 11:56
-
Simon Schaufelberger voted on patch set 1 CR +1 05/16/24, 09:09
-
Philipp Kitzberger commented on patch set 1 05/23/24, 07:53
I'm a bit confused by the commit message of this change. What do you mean by "respect" exactly? I would expect a custom cache without assignment to the 'all' group to be *not* flushed when flushing said group. -
Robert Kärner commented on patch set 1 06/10/24, 11:13
Reply Unresolved
Thank you Philipp for your feedback and your input on this issue. In general, there are three different ways to clear "all" TYPO3 caches: - By using the system toolbar in the backend (lightning bolt icon) - By using the "Flush cache" button in the `System Tools > Maintenance` section - By using the `vendor/bin/typo3 cache:flush` CLI command While the system toolbar way does not include flushing the dependency injection cache, the button in the install tool includes this DI cache and is the "fullest" option to clear all caches. At least, this is stated by the cache documentation, found at https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/CachingFramework/Index.html#clearing-flushing-and-warming-up-caches Further, the docs state that "The [CLI] command defaults to flush all available cache groups as the `System Tools > Maintenance` area does.", implying that it should work the same way as clicking the "Flush cache" button in the `System Tools > Maintenance` section. Now I've stated the different ways to clear "all caches", but how do they differ and what is my actual problem? The documentation states, that it should be enough to create a new custom cache by defining only the bare minimum of the configuration. https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/CachingFramework/Configuration/Index.html gives the example of: `$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myext_mycache'] ??= [];` By creating a custom cache like this, I as a developer expect it to be flushed as well when I ask TYPO3 to "flush all caches". Now, does it actually get flushed? - Using the system toolbar in the backend: Yes, the cache is flushed - Using the "Flush cache" button at `System Tools > Maintenance`: Yes, the cache is flushed - Running `vendor/bin/typo3 cache:flush` on the CLI: No, the cache is not flushed This contradicts the statement of the documentation, that the CLI command basically works the same as the `System Tools > Maintenance > Flush cache` method. So again, why does this happen? Clicking the Clear all caches button in the TYPO3 backend toolbar is ultimately executing `DataHandler::clear_cacheCmd('all')`, which calls `CacheManager::flushCaches()`, which flushes all caches defined in the `CacheManager::cacheConfigurations` array, where my custom `myext_mycache` is included. Clicking the `System Tools > Maintenance > Flush cache` button executes `ClearCacheService::clearAll()` which manually creates a new CacheManager, sets the cacheConfiguration array from `$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']` after loading all ext_localconf.php files, and then running `CacheManager::flushCaches()` again, basically giving the same result as clicking the backend toolbar button: the custom `myext_mycache` cache is flushed. Executing `vendor/bin/typo3 cache:flush` on the CLI works a bit different. I don't know why there are differences to the other methods, but the CLI command (`CacheFlushCommand::class`) is trying to make use of the `CacheFlushEvent`, and is in fact the only place where this event is actually dispached. The `CacheFlushEvent` only allows to pass an array of cache groups to be flushed. This array is fetched from `CacheManager::getCacheGroups()`, passed to `CacheFlushEvent`, catched by `CacheManager::handleCacheFlushEvent()` which calls `CacheManager::flushCachesInGroup()`. The problem lies in the fact, that `CacheManager::getCacheGroups()` only returns a list of cache groups that have been manually added to a cache configuration. If any cache is configured without using a cache group, it will never be included and flushed by using `vendor/bin/typo3 cache:flush`. This is unexpected behaviour, since it is not stated by the documentation that adding a cache group is mandatory for the CLI command to flush my custom cache. My solution in this patch makes use of the effect, that `CacheManager::class` defines a `CacheManager::defaultCacheConfiguration`, containing a special group called 'all' that gets added to all caches not defining any cache groups themselves. I would not call this a real group, since it comes with special behaviour. Even if you add the group name 'all' manually to a custom cache of yours, you won't be able to only flush that cache group 'all'. If you pass 'all' as an argument to `vendor/bin/typo3 cache:flush`, a special condition in CacheFlushCommand::execute is used that fetches all available cache groups instead (`$groups = $group === 'all' ? $container->get(CacheManager::class)->getCacheGroups() : [$group];`). So I personally **would** expect a custom cache without assignment to an 'all' group to be flushed, when flushing "all" caches. This is also the opinion of every of my developer coworkers that I have asked so far. All means all, and if this is even the default behaviour of the CLI command, I expect it to work according to the documentation. Please let me know if something is unclear and I should provide more background or input. -
Benjamin Franzke commented on patch set 1 CR -1 10/10/24, 16:01
Please see https://forge.typo3.org/issues/103127 – this is unneeded. The cache group `all` is properly returned if a cache is available with that group set. Make sure to properly registered the cache in @ext_localconf.php@, it can only be flushed if available. -
Benjamin Franzke commented on patch set 1 10/10/24, 16:02
Reply
> Please see https://forge.typo3.org/issues/103127 – this is unneeded. I actually wanted to directly refert to my comment on https://forge.typo3.org/issues/103127#note-2 -
Oliver Hader updated the commit message in patch set 2
CR +1V +110/18/24, 13:59 -
Benjamin Franzke voted on patch set 2 CR -1 10/18/24, 14:54
-
Benjamin Franzke abandoned the change 11/04/24, 15:26