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:

http://drupal.org/node/1841878

Files: 
CommentFileSizeAuthor
#18 interdiff-1841900-15-18.txt1.94 KBherom
#18 drupal-1841900-18.patch3.65 KBherom
PASSED: [[SimpleTest]]: [MySQL] 40,422 pass(es).
[ View ]
#15 drupal-1841900-15.patch2.69 KBherom
PASSED: [[SimpleTest]]: [MySQL] 40,480 pass(es).
[ View ]
#15 drupal-1841900-15-tests-only.patch2.33 KBherom
FAILED: [[SimpleTest]]: [MySQL] 40,431 pass(es), 2 fail(s), and 0 exception(s).
[ View ]
#12 drupal-1841900-12.patch4.43 KBolli
PASSED: [[SimpleTest]]: [MySQL] 58,734 pass(es).
[ View ]
#12 interdiff.txt877 bytesolli
#10 drupal-1841900-10.patch4.4 KBolli
PASSED: [[SimpleTest]]: [MySQL] 58,464 pass(es).
[ View ]
#6 node_deletion_clear_cache-1841900-tests-only.patch2.6 KBolli
FAILED: [[SimpleTest]]: [MySQL] 50,755 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#6 node_deletion_clear_cache-1841900-6.patch3.84 KBolli
PASSED: [[SimpleTest]]: [MySQL] 50,768 pass(es).
[ View ]
#4 node_deletion_clear_cache-1841878-4.patch386 bytesSheldon Rampton
PASSED: [[SimpleTest]]: [MySQL] 39,579 pass(es).
[ View ]
#1 node_deletion_clear_cache-1841878-1.patch393 bytesSheldon Rampton
PASSED: [[SimpleTest]]: [MySQL] 39,658 pass(es).
[ View ]

Comments

StatusFileSize
new393 bytes
PASSED: [[SimpleTest]]: [MySQL] 39,658 pass(es).
[ View ]

Here's a patch:

Status:Active» Needs review

It 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.

StatusFileSize
new386 bytes
PASSED: [[SimpleTest]]: [MySQL] 39,579 pass(es).
[ View ]

OK, here's an updated patch that also clears the entity cache.

Version:7.x-dev» 8.x-dev
Issue tags:+needs backport to D7

Nice find. Was this already fixed in D8?

StatusFileSize
new3.84 KB
PASSED: [[SimpleTest]]: [MySQL] 50,768 pass(es).
[ View ]
new2.6 KB
FAILED: [[SimpleTest]]: [MySQL] 50,755 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

Let's see. Moved cache invalidation to submit functions.

Status:Needs review» Needs work
Issue tags:-needs backport to D7

The last submitted patch, node_deletion_clear_cache-1841900-6.patch, failed testing.

Status:Needs work» Needs review
Issue tags:+needs backport to D7

Status:Needs review» Needs work

needs a reroll

Status:Needs work» Needs review
StatusFileSize
new4.4 KB
PASSED: [[SimpleTest]]: [MySQL] 58,464 pass(es).
[ View ]

Here we go.

thanks!
just two nitpicks i could find.

  1. +++ b/core/modules/node/lib/Drupal/node/Tests/NodePageCacheTest.php
    @@ -0,0 +1,90 @@
    +  function setUp() {
    ...
    +  function testNodeDelete() {

    need visibility

  2. +++ b/core/modules/node/lib/Drupal/node/Tests/NodePageCacheTest.php
    @@ -0,0 +1,90 @@
    +    \Drupal::config('system.performance')

    should use $this->container like:
    $this->container->get('config.factory')->get('system.performance');

StatusFileSize
new877 bytes
new4.43 KB
PASSED: [[SimpleTest]]: [MySQL] 58,734 pass(es).
[ View ]

Thank you!

Status:Needs review» Reviewed & tested by the community

thanks!
lets get it in!

Version:8.x-dev» 7.x-dev
Status:Reviewed & tested by the community» Patch (to be ported)

Nice find.

Committed f805ecf and pushed to 8.x. Thanks!

Issue summary:View changes
Status:Patch (to be ported)» Needs review
StatusFileSize
new2.33 KB
FAILED: [[SimpleTest]]: [MySQL] 40,431 pass(es), 2 fail(s), and 0 exception(s).
[ View ]
new2.69 KB
PASSED: [[SimpleTest]]: [MySQL] 40,480 pass(es).
[ View ]

backport patch to 7.x

Status:Needs review» Needs work

The last submitted patch, 15: drupal-1841900-15-tests-only.patch, failed testing.

hi herom, thanks for rolling this!

+++ b/modules/node/node.module
@@ -1286,6 +1286,7 @@ function node_delete_multiple($nids) {
+    cache_clear_all();

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()

Status:Needs work» Needs review
StatusFileSize
new3.65 KB
PASSED: [[SimpleTest]]: [MySQL] 40,422 pass(es).
[ View ]
new1.94 KB

new patch.

Status:Needs review» Reviewed & tested by the community

thanks looks good!

Status:Reviewed & tested by the community» Fixed
Issue tags:+7.25 release notes

Status:Fixed» Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.