Can't clear taxonomy cache in D6 - don't use static vars in D7

Just stumbled upon this core bug today and thought i would post for a couple reasons:

  1. i have written close to 100 D6 modules and somehow managed to never come across this
  2. it is pretty bad.. lol
  3. has been fixed in D7 with a cool new API call

The bottom line is simple:

there is no way in D6 to clear the taxonomy static cache

basically what this ends up meaning is:

can't set taxonomy on a node and then have a following node_load/node_save pair later in the same page load…

looking at the code for taxonomy_nodeapi and the function it calls: taxonomy_get_node_terms() it is pretty obvious. if you do a node_save this does not impact the static variable used in that function and therefore any subsequent node_loads will get the same taxonomy structure (NO!, doing a node_load with reset=true will have no impact on this).

Ideally i thnk what was needed would be for the node_load reset arg to be passed down through to subsequent nodeapi calls; but in D7 they took a different approach to fix this: drupal_static(). In D7 code, this should be used in place of static vars as it allows for external function to reset any other function's static variables.