It would be nice to have versions of these to call in our custom code.

Comments

dave reid’s picture

Title: Provide a rendered cache version of field_view_field() and field_view_value() » Provide a rendered cache version of field_view_field().
Category: Bug report » Task
Status: Active » Needs review
StatusFileSize
new8.73 KB

Re-scoped to just field_view_field since that's easier to cache than field_view_value(), the latter accepts an arbitrary item to render instead of actually relying on the field data.

dave reid’s picture

StatusFileSize
new10.67 KB

Revised version that re-uses a bit more code since there was a fair amount of work duplicating the entity rendering/caching code.

dave reid’s picture

StatusFileSize
new15.44 KB

New version adds support for hijacking views_handler_field_field via the render_cache_views sub-module. Tested and confirmed to work on Views using field displays.

dave reid’s picture

fabianx’s picture

This is great! Thanks so much.

The cleanup makes sense to me and the code re-use is nice.

I will probably get to a more detailed review in the next few days.

fabianx’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Patch (to be ported)

Committed and pushed to 7.x-1.x. Thanks!

I added the following interdiff:

diff --git a/render_cache.module b/render_cache.module
index 9fbe9c2..b015cb5 100644
--- a/render_cache.module
+++ b/render_cache.module
@@ -45,6 +45,7 @@ function render_cache_entity_view_callback($entities, $view_mode, $langcode = NU
   // Setup drupal_render style cache array.
   $cache_info = render_cache_cache_info_defaults();
   $cache_info['keys'] = array(
+    'render_cache',
     'entity',
     $entity_type,
     $view_mode,

instead of using just 'entity'.

If we need to change this, lets please discuss this in another issue.

Thanks for your great contribution.

This still needs a forward port to 7.x-2.x.

  • Fabianx committed 2b2cf4f on 7.x-1.x authored by Dave Reid
    Issue #2335117 by Dave Reid: Provide a rendered cache version of...
  • Fabianx committed d7981d1 on 7.x-1.x
    Issue #2335117: Use render_cache:entity as prefix.
    

  • Fabianx committed 3d21a55 on
    Issue #2335117: Ensure cache can be disabled in hook_default_cache_info...
  • Fabianx committed bb2319e on
    Issue #2335117: Revert cache keys prefix change.
    
fabianx’s picture

Nvm, I reverted the adding of render_cache: as prefix as its not really needed being in cache_render bin ...

Instead I added the following:

diff --git a/render_cache.module b/render_cache.module
index 9fbe9c2..5f3aee3 100644
--- a/render_cache.module
+++ b/render_cache.module
@@ -486,7 +486,11 @@ function render_cache_view_field($entity_type, $entity, $field_name, $display =
     'bundle' => $bundle,
   );
   $cid = render_cache_get_entity_cid($entity, $cache_info, $entity_context);
-  $cache = cache_get($cid, 'cache_render');
+
+  $cache = NULL;
+  if (isset($cache_info['granularity']) && $cache_info['granularity'] != DRUPAL_NO_CACHE) {
+    $cache = cache_get($cid, 'cache_render');
+  }
 
   if (!$cache) {
     $field_render = field_view_field($entity_type, $entity, $field_name, $display, $langcode);

to be consistent with the setting for entities.

geek-merlin’s picture

So this is fixed?

fabianx’s picture

#10 Yes, but not yet in 7.x-2.x it seems, so needs to still be ported ... I think ...