Index: node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.776.2.1 diff -u -p -r1.776.2.1 node.module --- node.module 29 Jan 2007 21:51:53 -0000 1.776.2.1 +++ node.module 8 Feb 2007 16:25:33 -0000 @@ -9,6 +9,14 @@ define('NODE_NEW_LIMIT', time() - 30 * 24 * 60 * 60); +// has to go here because needs to load before other hook_menus. Not needed for cached pages though. +function node_init(){ + global $memcache; + $memcache = new Memcache; + $memcache->connect('localhost', 11211) or die ('Could not connect to memcached'); + $memcache->drupal_prefix = variable_get('site_name', 'drupal') . 'node_load'; +} + /** * Implementation of hook_help(). */ @@ -484,17 +492,17 @@ function node_invoke_nodeapi(&$node, $op * A fully-populated node object. */ function node_load($param = array(), $revision = NULL, $reset = NULL) { - static $nodes = array(); + global $memcache; if ($reset) { - $nodes = array(); + memcache_flush($memcache); } $cachable = ($revision == NULL); $arguments = array(); if (is_numeric($param)) { - if ($cachable && isset($nodes[$param])) { - return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param]; + if ($cachable && ($mem_node = $memcache->get($memcache->drupal_prefix . $param))) { + return $mem_node; } $cond = 'n.nid = %d'; $arguments[] = $param; @@ -502,6 +510,9 @@ function node_load($param = array(), $re else { // Turn the conditions into a query. foreach ($param as $key => $value) { + if ($cachable && ($key == 'nid') && ($mem_node = $memcache->get($memcache->drupal_prefix . $value))){ + return $mem_node; + } $cond[] = 'n.'. db_escape_string($key) ." = '%s'"; $arguments[] = $value; } @@ -533,7 +544,7 @@ function node_load($param = array(), $re } } if ($cachable) { - $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node; + $memcache->set($memcache->drupal_prefix . $node->nid, $node); } } @@ -543,7 +554,7 @@ function node_load($param = array(), $re /** * Save a node object into the database. */ -function node_save(&$node) { +function node_save(&$node, $cache_flush = 1) { global $user; $node->is_new = FALSE; @@ -648,7 +659,11 @@ function node_save(&$node) { node_access_acquire_grants($node); // Clear the cache so an anonymous poster can see the node being added or updated. - cache_clear_all(); + if ($cache_flush) { + cache_clear_all(); + global $memcache; + $memcache->set($memcache->drupal_prefix . $node->nid, $node); + } }