? taxonomy_set_term.patch
? taxonomy_set_term_2.patch
Index: modules/taxonomy/taxonomy.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v
retrieving revision 1.422
diff -u -p -r1.422 taxonomy.module
--- modules/taxonomy/taxonomy.module	9 Jun 2008 07:28:35 -0000	1.422
+++ modules/taxonomy/taxonomy.module	23 Jun 2008 18:07:30 -0000
@@ -615,6 +615,7 @@ function taxonomy_node_get_terms($node, 
     $terms[$node->vid][$key] = array();
     while ($term = db_fetch_object($result)) {
       $terms[$node->vid][$key][$term->$key] = $term;
+      taxonomy_set_term($term->tid, $term);
     }
   }
   return $terms[$node->vid][$key];
@@ -997,6 +998,39 @@ function taxonomy_vocabulary_load($vid) 
 }
 
 /**
+ * Set and return the term matching a term ID.
+ * 
+ * @param $tid
+ *   A term's ID.
+ * 
+ * @param $term
+ *   A term.
+ * 
+ * @param $reset
+ *   Set this to true to refresh the term cache.
+ *
+ * @return Object|Boolean
+ *   A term object or boolean when no term was found. Results are statically cached.
+ */
+function taxonomy_set_term($tid, $term = null, $reset = null) {
+  static $terms = array();
+  
+  if ($reset == true) {
+    $terms = true;
+  }
+  
+  if (!isset($terms[$tid]) && isset($term)) {
+    $terms[$tid] = $term;
+  }
+  
+  if (isset($terms[$tid])) {
+    return $terms[$tid];
+  }
+  
+  return false;
+}
+
+/**
  * Return the term object matching a term ID.
  *
  * @param $tid
@@ -1005,14 +1039,12 @@ function taxonomy_vocabulary_load($vid) 
  * @return Object
  *   A term object. Results are statically cached.
  */
-function taxonomy_get_term($tid) {
-  static $terms = array();
-
-  if (!isset($terms[$tid])) {
-    $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid));
+function taxonomy_get_term($tid) {  
+  if (!$term = taxonomy_set_term($tid)) {
+    $term = taxonomy_set_term($tid, db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)));
   }
-
-  return $terms[$tid];
+  
+  return $term;
 }
 
 function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) {
