private synchronized void fetchAndUpdateCache(boolean isCalledFromListener) {
    Collection<Account> accounts = accountMetadataStore.fetchAccountMetadata();
    if (accounts == null) {
      logger.debug("No account collection returned");
    } else {
      logger.trace("Start parsing remote account data");
      AccountInfoMap newAccountInfoMap = new AccountInfoMap(accounts);
      AccountInfoMap oldAccountInfoMap = accountInfoMapRef.getAndSet(newAccountInfoMap);

      //Notify modified accounts to consumers
      Collection<Account> updatedAccounts = newAccountInfoMap.getAccounts()
          .stream()
          .filter(newAccount -> !newAccount.equals(oldAccountInfoMap.getAccountById(newAccount.getId())))
          .collect(Collectors.toSet());
      notifyAccountUpdateConsumers(updatedAccounts, isCalledFromListener);
    }
  }
A synchronized function to fetch account metadata from {@link AccountMetadataStore} and update the in memory cache.
@param isCalledFromListener True is this function is invoked in the {@link TopicListener}.
ambry-account/src/main/java/com/github/ambry/account/HelixAccountService.java