diff options
Diffstat (limited to 'modules/node/node.module')
-rw-r--r-- | modules/node/node.module | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/modules/node/node.module b/modules/node/node.module index ea156904a..9f21f1be3 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -450,6 +450,7 @@ function node_type_delete($type) { */ function node_type_update_nodes($old_type, $type) { db_query("UPDATE {node} SET type = '%s' WHERE type = '%s'", $type, $old_type); + cache_clear_all('*', 'cache_node', TRUE); return db_affected_rows(); } @@ -626,8 +627,17 @@ function node_load($param = array(), $revision = NULL, $reset = NULL) { $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) { + if (!isset($nodes[$param])) { + if ($cache = cache_get($param, 'cache_node')) { + $nodes[$param] = $cache->data; + } + } + // Either the node was statically cached or we loaded from the + // cache_node table. + if (isset($nodes[$param])) { + return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param]; + } } $cond = 'n.nid = %d'; $arguments[] = $param; @@ -670,6 +680,11 @@ function node_load($param = array(), $revision = NULL, $reset = NULL) { } if ($cachable) { $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node; + // We can only cache when a nid is given, otherwise the conditions are + // too dynamic to be cacheable. + if (is_numeric($param)) { + cache_set($param, $nodes[$node->nid], 'cache_node'); + } } } @@ -866,6 +881,8 @@ function node_save(&$node) { // Clear the page and block caches. cache_clear_all(); + // Clear the node load cache for this node. + cache_clear_all($node->nid, 'cache_node'); } /** @@ -1196,6 +1213,7 @@ function node_user($op, &$edit, &$user) { if ($op == 'delete') { db_query('UPDATE {node} SET uid = 0 WHERE uid = %d', $user->uid); db_query('UPDATE {node_revisions} SET uid = 0 WHERE uid = %d', $user->uid); + cache_clear_all('*', 'cache_node', TRUE); } } |