-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add missing observers for invalidating cache upon reindex #99
Conversation
@udovicic
and it's overkill. Magento 2 by default has this in module Magento_PageCache:
and in module Magento_CacheInvalidate:
Magento 2, for built-in full page cache and Varnish cache, will clean cache by tags in those 2 Observers. Cleaning/purging all cache from Faslty after each product doesn't look great too:
If there is something missing in Fastly_Cdn module, it should be coded in other manner. Maybe using like in Magento 2 default clean cache by tags observer: Fastly\Cdn\Observer\InvalidateVarnishObserver.
I don't know about 'controller_action_postdispatch_catalog_product_save' event. Also please take a look at this issue. It happens that we both are looking to same kind of issues: |
@udovicic
And with indexers set on Update by Schedule, I can confirm that rows are inserted in MView's changelog tables '[indexer_name]_cl'. Cron picks the changes and it will run indexers.
When indexers are set on Update on Save, I'm not particularly sure how exactly Varnish module Magento_CacheInvalidate cleans pages cache after product save in admin. Basically what I'm saying, in case of product save in admin, Magento 2 default code covers page cache cleaning (Fastly included too) with the existing events dispatched in the correct code context. |
Hi @daniel-ifrim, You are correct,there is an room from improvement for cleaning cache. Let me look into those, and I will try to cover the #98 as well. |
@daniel-ifrim can you verify if this addresses your concerns ? |
To share some more info on this, In my latest commit I have changed the way of purging cache, and now cache is purged by tags passed by the Magento framework (on same events). Therefore, cache that is still valid is preserved while the affected cache is purged. |
Please note that my feedback is based on Magento 2.1.0 - 2.1.7. I'm testing in 2.1.7 now.
For 'clean_cache_after_reindex':
Adding an observer for event 'controller_action_postdispatch_catalog_product_save' is redundant with Magento 2 core code.
Magento 2 already cleans cache too many times on product save. See bellow why. Most important is to add in Fastly_Cdn\etc\module.xml
Because you replaced 'invalidate_varnish' of Magento_CacheInvalidate (default Varnish module):
Only that Magento_CacheInvalidate is after Fastly_Cdn in app/etc/config.php Event 'clean_cache_by_tags' is important because it is the event responsible to clean full page cache selectively by cache tags. In case of Fastly_Cdn, the surrogate keys. I've tested in Magento 2.1.7, on product save 'clean_cache_by_tags' event is executed. If you want to make tests about cleaning cache on product save in admin, I'would suggest to use a simple product. This is the backtrace log file: |
Hi @daniel-ifrim, at first I have missed what you are saying. It was never my intention to override the observers, it was error in naming. I have adjusted. Also, the observer on admin action has been removed. Even though Magento core has it, it seems redundant after testing, so it was removed. Everything was tested on 2.1.8 and 2.2.-dev and appears to be working as expected. |
@udovicic Thank you. |
Add two missing events that were causing cache invalidation not to be triggered.
Example case would be saving category info with indexing mode set to 'on schedule' and 'flat tables' being turned on.