Saving or updating a node in Drupal triggers cache_clear_all(NULL, 'cache_page'). However, node deletion does not. Instead, node_delete_multiple() calls
<?php
entity_get_controller('node')->resetCache();
?>
which which clears a static cache but doesn't actually clear the cache in the database. It also fails to call
<?php
_cache_get_object($bin)->clear($cid, $wildcard);
?>
The result is that third-party caching modules such as Redis may fail to properly clear cache upon node deletion and will therefore return stale content.
I noticed this issue while researching a problem with cache clearing in the Redis module, which I have reported separately:
Comment | File | Size | Author |
---|---|---|---|
#18 | interdiff-1841900-15-18.txt | 1.94 KB | herom |
#18 | drupal-1841900-18.patch | 3.65 KB | herom |
#15 | drupal-1841900-15.patch | 2.69 KB | herom |
#15 | drupal-1841900-15-tests-only.patch | 2.33 KB | herom |
#12 | drupal-1841900-12.patch | 4.43 KB | olli |
Comments
Comment #1
Sheldon Rampton CreditAttribution: Sheldon Rampton commentedHere's a patch:
Comment #2
Sheldon Rampton CreditAttribution: Sheldon Rampton commentedComment #3
joshk CreditAttribution: joshk commentedIt might also want to clear the entity cache as well. That will prevent the $node object from appearing to continue to exist in later action in the same boostrap.
Comment #4
Sheldon Rampton CreditAttribution: Sheldon Rampton commentedOK, here's an updated patch that also clears the entity cache.
Comment #5
olli CreditAttribution: olli commentedNice find. Was this already fixed in D8?
Comment #6
olli CreditAttribution: olli commentedLet's see. Moved cache invalidation to submit functions.
Comment #8
olli CreditAttribution: olli commented#6: node_deletion_clear_cache-1841900-6.patch queued for re-testing.
Comment #9
ParisLiakos CreditAttribution: ParisLiakos commentedneeds a reroll
Comment #10
olli CreditAttribution: olli commentedHere we go.
Comment #11
ParisLiakos CreditAttribution: ParisLiakos commentedthanks!
just two nitpicks i could find.
need visibility
should use $this->container like:
$this->container->get('config.factory')->get('system.performance');
Comment #12
olli CreditAttribution: olli commentedThank you!
Comment #13
ParisLiakos CreditAttribution: ParisLiakos commentedthanks!
lets get it in!
Comment #14
alexpottNice find.
Committed f805ecf and pushed to 8.x. Thanks!
Comment #15
herom CreditAttribution: herom commentedbackport patch to 7.x
Comment #17
ParisLiakos CreditAttribution: ParisLiakos commentedhi herom, thanks for rolling this!
this call should happen in the form submit handlers not here, because, well, if you call that function many times programmatically, that would make things significantly slower;)
so this should go in node_delete_confirm_submit() and in node_multiple_delete_confirm_submit()
Comment #18
herom CreditAttribution: herom commentednew patch.
Comment #19
ParisLiakos CreditAttribution: ParisLiakos commentedthanks looks good!
Comment #20
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - thanks! http://drupalcode.org/project/drupal.git/commit/df93dd2