get the user by its Id, we can specify the cache if we want to
we only get result if the user is active

@param int $userId
@param boolean $cache

@return User
502332
public static function getById($userId, $cache = false) : Users
    {
        $options = null;
        $key = 'userInfo_' . $userId;

        if ($cache) {
            $options = ['cache' => ['lifetime' => 3600, 'key' => $key]];
        }

        if ($userData = Users::findFirstById($userId, $options)) {
            return $userData;
        } else {
            throw new Exception(_('The specified user does not exist in our database.'));
        }
    }
1043512
public static function getSessionWithUserId($userid)
	{
		// get list of all sessions
		$sessions = \App::get('session')->getStore()->all(array(
			'guest'    => 0,
			'distinct' => 1
		));

		// see if any session matches our userid
		foreach ($sessions as $session)
		{
			if ($session->userid == $userid)
			{
				return $session;
			}
		}

		// nothing found
		return null;
	}
107708
def get_authuser_by_userid(cls, request):
        
        userid = authenticated_userid(request)
        if userid:
            cache_request_user(cls, request, userid)
            return request._user
484667
public function deleteUserQuery($userId)
    {
        $qb = $this->createQueryBuilder();
        $qb->delete($this->getTableName());

        if (is_numeric($userId)) {
            $qb->where('id = :userId');
        } else {
            $qb->where('username = :userId')->orWhere('email = :userId');
        }
        $qb->setParameter('userId', $userId);

        return $qb;
    }
334359
public function get(&$cached) {
		if( static::$APCavailable ) {
			$fc = apc_fetch($this->key, $success);
		} else {
			$fc = false;
			$success = false;
		}
// 		$fc = static::$useAPCu ? apcu_fetch($this->key, $success) : apc_fetch($this->key, $success);
		if( $fc !== false ) {
			$cached = $fc;
		}
		return $success;
	}
1245908
protected static function cache_get_by_id($id) {
        if (isset(self::$cache_contextsbyid[$id])) {
            return self::$cache_contextsbyid[$id];
        }
        return false;
    }
1186648
static function getCacheDir( $userId = 0 )
    {
        $dir = eZSys::cacheDirectory() . '/user-info' . eZDir::createMultilevelPath( $userId, 5 );

        if ( !is_dir( $dir ) )
        {
            eZDir::mkdir( $dir, false, true );
        }
        return $dir;
    }
29951
public function UserCache($User) {
      $UserID = GetValue('UserID', $User, NULL);
      if (is_null($UserID) || !$UserID) return FALSE;
      
      $Cached = TRUE;
      
      $UserKey = FormatString(self::USERID_KEY, array('UserID' => $UserID));
      $Cached = $Cached & Gdn::Cache()->Store($UserKey, $User, array(
         Gdn_Cache::FEATURE_EXPIRY  => 3600
      ));
      
      $UserNameKey = FormatString(self::USERNAME_KEY, array('Name' => md5(GetValue('Name', $User))));
      $Cached = $Cached & Gdn::Cache()->Store($UserNameKey, $UserID, array(
         Gdn_Cache::FEATURE_EXPIRY  => 3600
      ));
      return $Cached;
   }
1241712
public User findUserById(String userId) {
    return createUserQuery(org.camunda.bpm.engine.impl.context.Context.getCommandContext())
      .userId(userId)
      .singleResult();
  }
953173
public function get($userId)
    {
        $endpoint = '/admin/users/'.$userId.'.json';
        $response = $this->request($endpoint);
        return $this->createObject(User::class, $response['user']);
    }
468841
public function getGoogleBatchServiceGmailForUserId(string $userId)
    {
        $email = $this->directory->resolvePrimaryEmailFromUserId($userId);
        if (array_key_exists($email, $this->googleBatchServiceGmails)) {
            return $this->googleBatchServiceGmails[$email];
        }

        $googleServiceGmail = new \Google_Service_Gmail($this->serviceAccount->getGoogleBatchClientForEmail($email));
        $this->googleBatchServiceGmails[$email] = $googleServiceGmail;

        return $googleServiceGmail;
    }
253534
public function get($documentId, $cache = true)
    {
        $rtn = $this->getCache($documentId);

        if (!$cache || !$rtn) {
            list($status, $doc) = $this->sendRequest(urlencode($documentId));

            if ($status == 200) {
                $rtn = $this->setCache($documentId, $doc);
            } else {
                $rtn = null;
            }
        }

        return $this->asDocs ? $this->toDocument($rtn) : $rtn;
    }
458821
public static function get($key)
    {
        if (!self::$instance) return null;

        return self::$instance->cache->get($key);
    }
56144
private function fetchFromCache(User $user)
    {
        return $this->hasCache($user) ? self::$cache[$user->getId()] : null;
    }
1363569
protected function getUser($id)
    {
        if (!isset($this->retrievedUsers[$id])) {
            $user = $this->userMapper->findById($id);
            $this->retrievedUsers[$id] = $user;
        }

        return $this->retrievedUsers[$id];
    }
1272239
public function ClearCache($UserID, $CacheTypesToClear = NULL) {
      if (is_null($UserID) || !$UserID) return FALSE;
      
      if (is_null($CacheTypesToClear))
         $CacheTypesToClear = array('user', 'roles', 'permissions');
      
      if (in_array('user', $CacheTypesToClear)) {
         $UserKey = FormatString(self::USERID_KEY, array('UserID' => $UserID));
         Gdn::Cache()->Remove($UserKey);
      }
      
      if (in_array('roles', $CacheTypesToClear)) {
         $UserRolesKey = FormatString(self::USERROLES_KEY, array('UserID' => $UserID));
         Gdn::Cache()->Remove($UserRolesKey);
      }
      
      if (in_array('permissions', $CacheTypesToClear)) {
         Gdn::SQL()->Put('User', array('Permissions' => ''), array('UserID' => $UserID));
         
         $PermissionsIncrement = $this->GetPermissionsIncrement();
         $UserPermissionsKey = FormatString(self::USERPERMISSIONS_KEY, array('UserID' => $UserID, 'PermissionsIncrement' => $PermissionsIncrement));
         Gdn::Cache()->Remove($UserPermissionsKey);
      }
      return TRUE;
   }
465681
public function find($user_id): ?User
    {
        return app('cache.array')->rememberForever(__CLASS__ . $user_id, static function () use ($user_id): ?User {
            return DB::table('user')
                ->where('user_id', '=', $user_id)
                ->get()
                ->map(User::rowMapper())
                ->first();
        });
    }