Skip to content

[Issue] Stop flushing fpc when not asked for #38301

@m2-assistant

Description

@m2-assistant

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 (*)

  1. 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();
         }
  1. Use built-in FPC
  2. Run bin/magento cache:flush and bin/magento cache:clean => expected to hit one of those die statements introduced in step 1
  3. Run bin/magento cache:flush full_page and bin/magento cache:clean full_page => expected to hit one of those die statements introduced in step 1
  4. Run bin/magento cache:flush layout and bin/magento cache:clean layout => expected to not hit one of those die statements introduced in step 1
  5. Configure FPC to use Varnish
  6. 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

Labels

Area: CatalogIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions