Skip to content

Too many 'clean cache by tags' actions, with same tags, when saving entities and/or running full reindex #32780

@antoinekociuba

Description

@antoinekociuba

Hi there,

After digging on clean cache by tags mechanism from the back office (save product, category, CMS block and CMS page) and from the CLI full reindex, I have notice that clean_cache_by_tags event is dispatched multiple times, at different places, which could makes sense, but also triggers many duplicated clean cache calls, with mostly same tag(s) to clean, which becomes pretty useless and overkill.

  • When Built-in FPC is used, it means that we do multiple same clean calls to Redis when it could be avoided.
  • When Varnish FPC is used, it means that we do multiple same purge requests to it, when it also could be avoided.
  • When using something else, such as Cloudflare CDN as FPC engine, with a limitation of 30,000 purge API calls in a 24-hour period, it means that we may not be able to flush what is needed all the time, when it also could be much more possible without duplicates.

I enclosed below some logs with backtraces on different kind of entities/actions:

cache_clean_category.log
cache_clean_cms_block.log
cache_clean_cms_page.log
cache_clean_configurable_product_index_save.log
cache_clean_configurable_product_index_schedule.log
cache_clean_full_reindex.log
cache_clean_simple_product_index_save.log
cache_clean_simple_product_index_schedule.log

Preconditions (*)

  1. Magento Open Source 2.4.2

Steps to reproduce (*)

  1. Add a log in Magento\CacheInvalidate\Observer\InvalidateVarnishObserver PHP class or in Magento\PageCache\Observer\FlushCacheByTags PHP class.
  2. Save different types of entities from the back office (product, category, CMS block and CMS page), with indexers set on 'Update on Save' and/or 'Update on Schedule.'
  3. And also run a full reindex from CLI.

Expected result (*)

Do not trigger duplicated cache clean actions with the exact same cache tags mostly, and reduce number of cache clean actions in the same execution thread (less connexions/traffic to Redis/Varnish/Anything else).

It could be nice to have a kind of 'Tags to clean' collector object, which will be responsible to collect, obviously, and to launch, at the very end of any save actions and/or full reindex CLI process, only one or needed cache clean calls, without any duplicated tags.

Actual result (*)

  1. Multiple cache clean calls, with mostly same cache tags.

Thank you in advance for your help and your consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: CatalogComponent: CacheComponent: PageCacheIssue: 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: ready for devReported on 2.4.2Indicates original Magento version for the Issue report.Reproduced 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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions