Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Why is it that node_delete (which calls node_delete_multiple) empties all node cache even though it has the list of specific nids?

I have 200K+ records, all of which I would like to cache pre-emptively by entitycache module + Drush Entity Cache Loader (ECL). This is (obv) an expensive operation - but deleting even one node empties entire cache.

I realize that I can simply modify entitycache module to do exactly what I want - but I am just wondering about the rationale behind emptying entire cache.

share|improve this question
    
How can we know? DrupalEntityControllerInterface::resetCache(array $ids = NULL) accepts list of IDs, but only developers can know why they decided not to use it in this case. And if you want to ask them, you should post a support request on drupal.org - here we could only guess and provide our opinions - not what this site is for. –  Mołot Mar 28 at 8:11
add comment

2 Answers 2

up vote 5 down vote accepted

One reason i see is Entity Reference...

For Example -

  • A block which lists some nodes part of your delete list.
  • A node which has entity reference to your deleted node
  • A view page which has some of your deleted nodes

Reason for clearing all the caches: When a node is created/updated/deleted there can be many pages in the site which are dependent on the current node in question. It is next to impossible/very difficult identify all the dependencies and clear the caches only for those pages. For this particular reason, to make sure that no stale data is served to the end user drupal by default clears all the caches.

So, It makes sense to Clear the page and block and node_load_multiple caches as documented in node_delete_multiple function.

share|improve this answer
add comment

Short Answer : This is as per design. You are relying on Page Caching and it cannot differentiate whether it is a node page or any other page. So it clears all the caches. But you can override this behavior.

If you want to know more about why it is as per design read my answer Whenever I edit/update a node all the page caches for anonymous user are lost

In the answer I have also included the possible work-around for the same.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.