-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
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 (*)
- Magento Open Source 2.4.2
Steps to reproduce (*)
- Add a log in
Magento\CacheInvalidate\Observer\InvalidateVarnishObserver
PHP class or inMagento\PageCache\Observer\FlushCacheByTags
PHP class. - 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.'
- 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 (*)
- Multiple cache clean calls, with mostly same cache tags.
Thank you in advance for your help and your consideration.