Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.909
diff -u -p -r1.909 user.module
--- modules/user/user.module	26 May 2008 17:12:55 -0000	1.909
+++ modules/user/user.module	3 Jun 2008 18:32:07 -0000
@@ -140,23 +140,40 @@ function user_external_login($account, $
  * @param $array
  *   An associative array of attributes to search for in selecting the
  *   user, such as user name or e-mail address.
+ * @param $reset
+ *   If TRUE, clear all user objects from the static cache.
  *
  * @return
  *   A fully-loaded $user object upon successful user load or FALSE if user
  *   cannot be loaded.
  */
-function user_load($array = array()) {
-  // Dynamically compose a SQL query:
-  $query = array();
-  $params = array();
-
+function user_load($array = array(), $reset = FALSE) {
+  static $users = array();
+  
+  if ($reset) {
+    // Clear cached data.
+    $users = array();
+  }
+  
+  $cacheable = FALSE;
   if (is_numeric($array)) {
+    $uid = $array;
+    // Retun the cached data if it's available.
+    if (isset($users[$uid])) {
+      return empty($users[$uid]) ? FALSE : clone $users[$uid];
+    }
+    // Only cache data when we have a simple numeric parameter.
+    $cachable = TRUE;
     $array = array('uid' => $array);
   }
   elseif (!is_array($array)) {
     return FALSE;
   }
 
+  // Dynamically compose a SQL query:
+  $query = array();
+  $params = array();
+
   foreach ($array as $key => $value) {
     if ($key == 'uid' || $key == 'status') {
       $query[] = "$key = %d";
@@ -193,6 +210,10 @@ function user_load($array = array()) {
     $user = FALSE;
   }
 
+  if ($cachable) {
+    // Always use clone to avoid inadvertant modification of the cached object.
+    $users[$uid] = empty($user) ? FALSE : clone $user;
+  }
   return $user;
 }
 
