How to cache a node_load_multiple I'm loading 5 media gallery nodes into a single page via node_load_multiple().  Unfortunately the load time is very slow, several seconds.  I read up on Drupal's caching mechanism, and Jeff Eaton's tutorial and got the idea that I could cache each gallery node via the #cache array on the node's renderable array.  I think I've set everything up correctly, but I'm not seeing any increase in performance.  Any idea what I've done wrong or neglected to include?  Here's what I've done on a page.tpl.php for the page that contains the galleries:

$nodes = node_load_multiple($nids = array(1653,1654,1656,1657,1658), NULL, FALSE);
$i = 0;
$cid = "gallery_cache";
foreach ($nodes as $gallery) {
  $renderable = node_view($gallery);
  $cid .= $i;
  $renderable['#cache']['cid'] = $cid;
  $renderable['#cache']['bin'] = 'cache_page';
  $renderable['#cache']['expire'] = '1392001200';
  print drupal_render($renderable);
  $i++;
}
The results from node_load_multiple() are already cached within a single page load - the only time they're not is if you pass the $reset parameter as TRUE (which you're explicitly not doing). Looking at the code calls to node_view() don't seem to be cached, but I might be wrong there.

At a guess your performance hit might be coming from those individual calls to node_view(), which you might be able to mitigate a bit by using node_view_multiple() instead.

$nodes = node_load_multiple(array(1653,1654,1656,1657,1658));
$views = node_view_multiple($nodes);

foreach ($views as $view) {
  // ...
}


I'm pretty sure the reason your code isn't working as you expect is that the return from node_view() isn't a reference to anything, so the changes you're making to the array aren't actually getting saved anywhere, only to the local copy of the array.

One last piece of advice...it would be a good idea to take this code out of the template file and put it in a preprocess function at the the theme or module level. Running database queries directly in the template file isn't the best idea for a number of reasons.