-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
This issue is automatically created based on existing pull request: #38215: Stop flushing fpc when not asked for
Description (*)
We found out by surprise today on Slack (thanks @benjamin-volle & @robinero) that running bin/magento cache:clean
or bin/magento cache:flush
will always flush FPC (built-in or Varnish) entirely, even if you've only provided a type to be cleaned like config
, layout
, ...
I understand that yes, probably if one of those types get flushed, you'll most likely want to flush FPC as well, but let that be up to the user to decide by seeing if they provided the type full_page
explicitly in the command.
This fixes this.
Some history of this problem, flushing FPC via CLI got introduced at the request of #2025 and got fixed by c75c203
This PR enhances this a bit and will only dispatch those 2 events when either no types were provided in the command line or when full_page
is one of the types provided.
Related Pull Requests
Fixed Issues (if relevant)
No idea
Manual testing scenarios (*)
- Modify this code like so:
diff --git a/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php b/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php
index 574263ca1ee..1db01887467 100644
--- a/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php
+++ b/app/code/Magento/CacheInvalidate/Observer/FlushAllCacheObserver.php
@@ -45,6 +45,8 @@ class FlushAllCacheObserver implements ObserverInterface
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
+ die(sprintf("Flusing FPC in %s\n", $this::class));
+
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) {
$this->purgeCache->sendPurgeRequest(['.*']);
}
diff --git a/app/code/Magento/PageCache/Observer/FlushAllCache.php b/app/code/Magento/PageCache/Observer/FlushAllCache.php
index 6bcfd0e38df..d7684e25d4c 100644
--- a/app/code/Magento/PageCache/Observer/FlushAllCache.php
+++ b/app/code/Magento/PageCache/Observer/FlushAllCache.php
@@ -62,6 +62,8 @@ class FlushAllCache implements ObserverInterface
*/
public function execute(Observer $observer)
{
+ die(sprintf("Flushing FPC in %s\n", $this::class));
+
if ($this->_config->getType() === Config::BUILT_IN) {
$this->fullPageCache->clean();
}
- Use built-in FPC
- Run
bin/magento cache:flush
andbin/magento cache:clean
=> expected to hit one of thosedie
statements introduced in step 1 - Run
bin/magento cache:flush full_page
andbin/magento cache:clean full_page
=> expected to hit one of thosedie
statements introduced in step 1 - Run
bin/magento cache:flush layout
andbin/magento cache:clean layout
=> expected to not hit one of thosedie
statements introduced in step 1 - Configure FPC to use Varnish
- Run steps 3 to 5 again
Questions or comments
Since we introduced Magento\PageCache
in the Magento_Backend
module, should we add magento/module-page-cache
as dependency in the Backend module's composer.json
file? We can also choose to hardcode full_page
and don't use the constant, that's also an option ...
Update: looks like the automated tests also picked this up, I already force-pushed a change to have it hardcoded instead of using a constant from another module, adding a dependency might be out of scope here.
I noticed that the New Relic module also listens for that adminhtml_cache_flush_system
event, but it's done in the adminhtml/events.xml
file, so that should be fine since it's in the adminhtml
area. Running those cli commands wouldn't have triggered this observer anyways. So no regression there.
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- All automated tests passed successfully (all builds are green)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status