19 package org.sleuthkit.autopsy.communications;
21 import com.google.common.cache.CacheBuilder;
22 import com.google.common.cache.CacheLoader;
23 import com.google.common.cache.LoadingCache;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.TimeUnit;
29 import java.util.logging.Level;
41 final class CVTPersonaCache {
43 private static final Logger logger = Logger.getLogger(CVTPersonaCache.class.getName());
44 private final LoadingCache<Account, List<PersonaAccount>> accountMap;
46 private static CVTPersonaCache instance;
51 private CVTPersonaCache() {
52 accountMap = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build(
53 new CacheLoader<Account, List<PersonaAccount>>() {
55 public List<PersonaAccount> load(Account key) {
56 List<PersonaAccount> accountList =
new ArrayList<>();
58 if (CentralRepository.isEnabled()) {
59 Collection<PersonaAccount> accounts = PersonaAccount.getPersonaAccountsForAccount(key);
60 accountList.addAll(accounts);
62 }
catch (CentralRepoException ex) {
63 logger.log(Level.WARNING, String.format(
"Unable to load Persona information for account: %s", key), ex);
76 private static synchronized CVTPersonaCache getInstance() {
77 if (instance == null) {
78 instance =
new CVTPersonaCache();
93 static synchronized List<PersonaAccount> getPersonaAccounts(Account account)
throws ExecutionException {
94 return getInstance().accountMap.get(account);