Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently, any page that has this block on and has updated query string would have the Dynamic Page Cache invalidated. This happens because contexts
should be url.path
rather then url
- this is to make sure that adding query path does not invalidate this block's dynamic page cache.
Also, contexts
and tags
are not merged with parent tags making it impossible to alter tags for this block plugin.
Comment | File | Size | Author |
---|---|---|---|
#12 | social_media-dynamic-page-cache-invalidated-url-query-2931644-12.patch | 1.16 KB | scuba_fly |
Comments
Comment #2
alex.skrypnykAttached patch resolves this issue by using
getCacheTags()
andgetCacheContexts()
.Comment #3
gargsuchi CreditAttribution: gargsuchi at Salsa Digital for Department of Premier and Cabinet - Victoria, Australia commentedComment #4
MiroslavBanov CreditAttribution: MiroslavBanov as a volunteer and at FFW commentedThere is no need to initialize the cache tags and contexts in the constructor and there is no need to call the methods at all, as BlockViewBuilder::viewMultiple will call them.
See for example SystemMenuBlock code for how this is done in core.
Comment #5
MiroslavBanov CreditAttribution: MiroslavBanov as a volunteer and at FFW commentedThis patch is only making the fix without making the other code style related changes.
Comment #6
MiroslavBanov CreditAttribution: MiroslavBanov as a volunteer and at FFW commentedThis one also includes the code style things from the previous patch. Both patches work for me equally well.
Comment #7
scuba_flyI would go for patch #5 and commit the codestyle fixes in a different commit.
Comment #8
scuba_flyHmm
#5 does not add the getCache methods.
I think we need a new patch.
Comment #9
MiroslavBanov CreditAttribution: MiroslavBanov as a volunteer and at FFW commented@scuba_fly
#5 doesn't add the getCache methods, and #6 adds them.
So I am not sure are you saying both patches are not good and we need a new one? Please elaborate what this new patch should have? :)
Comment #10
scuba_flylet's make a new patch that fixes this with getCache methods.
So patch #6 without the codestyle fixes.
The codestyle fixes are in this issue #3001090: Coding standard
The reason to do it separately, is so it is more clear, and less chance of merge conflicts, giving it a better change other patches still apply.
Comment #11
MiroslavBanov CreditAttribution: MiroslavBanov as a volunteer and at FFW commentedNew patch per #10
Comment #12
scuba_flyThank you @MiroslavBanov
Made a new patch that applies to the latest dev version.
Added in the
'config:social_media.settings'
Does this make sense?
Added this line.
Cannot make an interdiff because of changes on the dev branch.
Comment #13
MiroslavBanov CreditAttribution: MiroslavBanov as a volunteer and at FFW commentedIt makes perfect sense. I also tested it on a new Drupal installation, and it worked as expected.
If trying to test, keep in mind that Toolbar module currently disables dynamic page cache, so test with Toolbar disabled.
Comment #15
scuba_flyThank you for your work and testing MiroslavBanov!
committed the last patch.
Comment #16
scuba_flyComment #17
ahebrank CreditAttribution: ahebrank commented@scuba_fly, please see https://www.drupal.org/project/social_media/issues/3089976 -- commit https://git.drupalcode.org/project/social_media/commit/fe6aeb3 is missing a necessary `use` statement.