I saw a possibility in radioactivity.rules.inc to clear only affected entity field cache instead of all field cache there is, but I'm wondering if this would not break existing functionality?

The actual patch is very small:

+++ radioactivity.rules.inc	2012-12-18 13:36:53.928377264 +0200
@@ -123,7 +123,8 @@
   if ($profile && $profile->storageObject) {
     $profile->storageObject->addIncident(new RadioactivityIncident($entity_type, $bundle, $field_name, $lang, $id, $energy, time()));
   }
-  field_cache_clear();
+
+  cache_clear_all("field:$entity_type:$id", 'cache_field');
 }
 
 /**
@@ -153,7 +154,7 @@
     TRUE
   );
 
-  field_cache_clear();
+  cache_clear_all("field:$entity_type:$id", 'cache_field');
 }
 
 /**
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jrbeeman’s picture

Version: 7.x-2.7 » 7.x-2.x-dev
Category: feature » bug
FileSize
1.5 KB

Updated against latest 7.x-2.x and added similar patch for emit.php. Changed category to bug report as this is a pretty huge performance drain on large sites with lots of user content creation. Without this patch, cache_field churns heavily.

jrbeeman’s picture

Follow-up: radioactivity_cron() still calls field_cache_clear() and this needs to be resolved.

jrbeeman’s picture

Title: Possible optimization of field cache clearing in rules' actions » Performance: Optimization of field cache clearing in rules actions, hook_cron, and emit.php
Status: Needs review » Needs work

Marking as needs work in order to resolve the hook_cron() implementation. Updated issue title to be more descriptive.

tcmug’s picture

Issue summary: View changes

We can't use db_delete to clear caches as it would not work for example memcache or redis caches, right?

So, in that regard this also needs work.

Heine’s picture

Status: Needs work » Needs review
FileSize
2.02 KB

Includes #1. Contains in addition a change to hook_cron to only clear field:[entity_type]: . This could be further optimised when rules is present by keeping an array of item ids and only clearing ids.

Patch is against 7.x-2.9.

Heine’s picture

Note that the patch in #5 doesn't prevent field cache clears from negatively affecting the site's performance; check_markup is called again and again for textfields with cacheable formats on load, because the field cache for the particular entity will be empty (see text_field_load()).