diff --git modules/node/node.module modules/node/node.module index e601f22..bbbff33 100644 --- modules/node/node.module +++ modules/node/node.module @@ -46,6 +46,11 @@ define('NODE_BUILD_RSS', 4); define('NODE_BUILD_PRINT', 5); /** + * Maximum number of nodes to retain in the node_load static cache + */ +define('NODE_LOAD_MAX_CACHE', 20); + +/** * Implementation of hook_help(). */ function node_help($path, $arg) { @@ -923,10 +928,24 @@ function node_load_multiple($nids = array(), $conditions = array(), $reset = FAL $function = $module . '_nodeapi_load'; $function($queried_nodes, array_keys($typed_nodes)); } - $nodes += $queried_nodes; + + // Add the current nodes that came from the cache to the end of the + // nodes so they will get purged after the newly loaded nodes. + $nodes+= $queried_nodes; // Add nodes to the cache if we're not loading a revision. if (!$vid) { - $node_cache += $queried_nodes; + $node_cache = $nodes + $node_cache; + + // check if the cache is greater than the max cache size and purge + // the nodes at the bottom of the array as they are the least used. + if (count($node_cache) > NODE_LOAD_MAX_CACHE) { + // TODO: These messages need to be removed before this is committed. + drupal_set_message(format_plural(count($node_cache)-NODE_LOAD_MAX_CACHE, 'Purge @count node from static cache', 'Purge @count nodes from static cache'), 'warning'); + $node_chunks = array_chunk($node_cache, NODE_LOAD_MAX_CACHE, TRUE); + $node_cache = $node_chunks[0]; + + drupal_set_message(format_plural(count($node_cache), '@count node remaining in static cache', '@count nodes remaining static cache'), 'warning'); + } } }