You are here

function _user_stats_user_cache in User Stats 5

User cache for optimisation, this needs to be a seperate function so cache can be flushed by user_stats_post_count_update below (and possibly other places).

Parameters

$uid: User id of user required from cache.

$flush: Defaults to FALSE. If TRUE the $uid is flushed from the cache. If $uid is set to -1 and $flush is TRUE the entire cache will be purged.

Return value

If the $uid is other than -1 and $flush is FALSE the user object. If the $uid is -1 and/or $flush is TRUE nothing.

2 calls to _user_stats_user_cache()
user_stats_get_stats in ./user_stats.module
Returns user stats.
user_stats_post_count_update in ./user_stats.module
Manage the post count of a given user.

File

./user_stats.module, line 291
User Stats provides commonly requested user statistics for themers. These are:

Code

function _user_stats_user_cache($uid, $flush = FALSE) {
  static $users = array();

  // Flush entire cache.
  if ($uid == -1 && $flush == TRUE) {
    unset($users);
    return;
  }
  else {
    if ($uid > -1 && $flush == TRUE) {
      unset($users[$uid]);
      return;
    }
    else {
      if (!isset($users[$uid]) && $uid > -1) {
        $users[$uid] = user_stats_user_load($uid);
      }
    }
  }
  return $users[$uid];
}