Recipient getRecipient(Context context, long recipientId, boolean asynchronous) { Recipient cachedRecipient = recipientCache.get(recipientId); if (cachedRecipient != null && !cachedRecipient.isStale()) return cachedRecipient; String number = CanonicalAddressDatabase.getInstance(context).getAddressFromId(recipientId); if (asynchronous) { cachedRecipient = new Recipient( recipientId, number, cachedRecipient, getRecipientDetailsAsync(context, recipientId, number)); } else { cachedRecipient = new Recipient(recipientId, getRecipientDetailsSync(context, recipientId, number)); } recipientCache.set(recipientId, cachedRecipient); return cachedRecipient; }
void clearCache() { recipientCache.reset(); recipientsCache.reset(); }