Stop flushing entire entity load cache bins unnecessarily

Created on 11 April 2013, over 11 years ago
Updated 25 November 2020, almost 4 years ago

Resetting an entity_load cache bin in Drupal 7 can have more drastic consequences than in previous versions of Drupal, as we can have persistent load caches in place of the PHP static memory cache. Wherever possible, we should flush only the necessary entities.

My understanding and reasoning for this patch is as follows:

No Drupal code ever has reason to distrust the entity load cache unless it specifically knows that the entity data has been directly modified (e.g. via direct database queries) but not also flushed from the load cache at that time. It is the responsibility of any code making such direct modifications to flush those entities from the cache. None of the functions in this patch are making any such direct changes to node data, and therefore they should trust that the cached nodes are valid.

The patch converts the usages of the $reset argument to the various entity_load() type functions in Drupal core to use targeted entity_get_controller($entity_type)->resetCache(array($entity_id)); calls instead.

In addition, calls to resetCache() with no argument (which is equivalent to the $reset=TRUE scenario) are also converted to use arguments where appropriate.

The code instances in the original version of the patch are in _node_mass_update_helper() and node_access_rebuild(), so I've specified the node component for this issue.

The patch also updates the @param $reset comments for the various entity load functions, recommending resetCache() as the preferred approach, and making them all more consistent with one another (as well as a little more general, given that the cache mechanism is pluggable).

🐛 Bug report
Status

RTBC

Version

7.0 ⚰️

Component
Node system 

Last updated 1 minute ago

No maintainer
Created by

🇳🇿New Zealand jweowu

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024