Index: user.module
===================================================================
--- user.module	(revision 1025)
+++ user.module	(working copy)
@@ -134,23 +134,40 @@
  *   - An associative array whose keys are fields in the {users} table (such as
  *     uid, name, pass, mail, status) and whose values are the field's value.
  *   - A numeric user ID.
+ * @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($user_info = 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();
 
-  if (is_numeric($user_info)) {
-    $user_info = array('uid' => $user_info);
-  }
-  elseif (!is_array($user_info)) {
-    return FALSE;
-  }
-
   foreach ($user_info as $key => $value) {
     if ($key == 'uid' || $key == 'status') {
       $query[] = "$key = %d";
@@ -187,8 +204,12 @@
     $user = FALSE;
   }
 
+  if ($cachable) {
+    // Always use clone to avoid inadvertant modification of the cached object.
+    $users[$uid] = empty($user) ? FALSE : clone $user;
+  }
   return $user;
-}
+} 
 
 /**
  * Save changes to a user account or add a new user.
