Package com.google.gerrit.server.account
Class AccountCacheImpl
- java.lang.Object
-
- com.google.gerrit.server.account.AccountCacheImpl
-
- All Implemented Interfaces:
AccountCache
public class AccountCacheImpl extends Object implements AccountCache
Caches important (but small) account state to avoid database hits.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<AccountState>
get(Account.Id accountId)
Returns anAccountState
instance for the given account ID.Map<Account.Id,AccountState>
get(Set<Account.Id> accountIds)
Returns aMap
ofAccount.Id
toAccountState
for the given account IDs.Optional<AccountState>
getByUsername(String username)
Returns anAccountState
instance for the given username.AccountState
getEvenIfMissing(Account.Id accountId)
Returns anAccountState
instance for the given account ID.static com.google.inject.Module
module()
-
-
-
Method Detail
-
module
public static com.google.inject.Module module()
-
getEvenIfMissing
public AccountState getEvenIfMissing(Account.Id accountId)
Description copied from interface:AccountCache
Returns anAccountState
instance for the given account ID. If not cached yet the account is loaded. Returns an emptyAccountState
instance to represent a missing account.This method should only be used in exceptional cases where it is required to get an account state even if the account is missing. Callers should leave a comment with the method invocation explaining why this method is used. Most callers of
AccountCache
should useAccountCache.get(Account.Id)
instead and handle the missing account case explicitly.- Specified by:
getEvenIfMissing
in interfaceAccountCache
- Parameters:
accountId
- ID of the account that should be retrieved- Returns:
AccountState
instance for the given account ID, if no account with this ID exists an emptyAccountState
instance is returned to represent the missing account
-
get
public Optional<AccountState> get(Account.Id accountId)
Description copied from interface:AccountCache
Returns anAccountState
instance for the given account ID. If not cached yet the account is loaded. ReturnsOptional.empty()
if the account is missing.- Specified by:
get
in interfaceAccountCache
- Parameters:
accountId
- ID of the account that should be retrieved- Returns:
AccountState
instance for the given account ID, if no account with this ID existsOptional.empty()
is returned
-
get
public Map<Account.Id,AccountState> get(Set<Account.Id> accountIds)
Description copied from interface:AccountCache
Returns aMap
ofAccount.Id
toAccountState
for the given account IDs. If not cached yet the accounts are loaded. If an account can't be loaded (e.g. because it is missing), the entry will be missing from the result.Loads accounts in parallel if applicable.
- Specified by:
get
in interfaceAccountCache
- Parameters:
accountIds
- IDs of the account that should be retrieved- Returns:
Map
ofAccount.Id
toAccountState
instances for the given account IDs, if an account can't be loaded (e.g. because it is missing), the entry will be missing from the result
-
getByUsername
public Optional<AccountState> getByUsername(String username)
Description copied from interface:AccountCache
Returns anAccountState
instance for the given username.This method first loads the external ID for the username and then uses the account ID of the external ID to lookup the account from the cache.
- Specified by:
getByUsername
in interfaceAccountCache
- Parameters:
username
- username of the account that should be retrieved- Returns:
AccountState
instance for the given username, if no account with this username exists or if loading the external ID failsOptional.empty()
is returned
-
-