def METHOD_NAME(self, userid_or_username, authority=None):
    """
    Fetch a user by userid or by username and authority.
    Takes *either* a userid *or* a username and authority as arguments.
    For example::
      user_service.fetch('acct:foo@example.com')
    or::
      user_service.fetch('foo', 'example.com')
    :returns: a user instance, if found
    :raises InvalidUserId: If the userid cannot be parsed
    :rtype: h.models.User or None
    """
    if authority is not None:
        username = userid_or_username
    else:
        userid = userid_or_username
        parts = split_user(userid)
        username = parts["username"]
        authority = parts["domain"]
    # The cache is keyed by (username, authority) tuples.
    cache_key = (username, authority)
    if cache_key not in self._cache:
        self._cache[cache_key] = (
            self.session.query(User)
            .filter_by(username=username)
            .filter_by(authority=authority)
            .one_or_none()
        )
    return self._cache[cache_key]