public interface AccountCache
Modifier and Type | Method and Description |
---|---|
void |
evict(Account.Id accountId)
Evicts the account from the cache.
|
void |
evictAll()
Evict all accounts from the cache.
|
java.util.Optional<AccountState> |
get(Account.Id accountId)
Returns an
AccountState instance for the given account ID. |
java.util.Map<Account.Id,AccountState> |
get(java.util.Set<Account.Id> accountIds)
Returns a
Map of Account.Id to AccountState for the given account IDs. |
java.util.Optional<AccountState> |
getByUsername(java.lang.String username)
Returns an
AccountState instance for the given username. |
AccountState |
getEvenIfMissing(Account.Id accountId)
Returns an
AccountState instance for the given account ID. |
java.util.Optional<AccountState> get(Account.Id accountId)
AccountState
instance for the given account ID. If not cached yet the
account is loaded. Returns Optional.empty()
if the account is missing.accountId
- ID of the account that should be retrievedAccountState
instance for the given account ID, if no account with this ID
exists Optional.empty()
is returnedjava.util.Map<Account.Id,AccountState> get(java.util.Set<Account.Id> accountIds)
Map
of Account.Id
to AccountState
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.
accountIds
- IDs of the account that should be retrievedMap
of Account.Id
to AccountState
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 resultAccountState getEvenIfMissing(Account.Id accountId)
AccountState
instance for the given account ID. If not cached yet the
account is loaded. Returns an empty AccountState
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 use get(Account.Id)
instead and handle the missing account case explicitly.
accountId
- ID of the account that should be retrievedAccountState
instance for the given account ID, if no account with this ID
exists an empty AccountState
instance is returned to represent the missing accountjava.util.Optional<AccountState> getByUsername(java.lang.String username)
AccountState
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.
username
- username of the account that should be retrievedAccountState
instance for the given username, if no account with this username
exists or if loading the external ID fails Optional.empty()
is returnedvoid evict(Account.Id accountId)
accountId
- account ID of the account that should be evictedvoid evictAll()