public async Task <Contact> GetAsync(Identity identity, CancellationToken cancellationToken) { if (!_configuration.ContactCacheEnabled) { return(await _contactExtension.GetAsync(identity, cancellationToken)); } var key = CreateKey(identity); Contact contact = null; try { contact = await _contactMap.GetValueOrDefaultAsync(key, cancellationToken); } catch (JsonSerializationException e) {} if (contact == null) { contact = await _contactExtension.GetAsync(identity, cancellationToken); if (contact != null) { await AddToCacheAsync(contact, key, cancellationToken); } } return(contact); }
public async Task <Contact> GetAsync(Identity identity, CancellationToken cancellationToken) { if (!_configuration.ContactCacheEnabled) { return(await _contactExtension.GetAsync(identity, cancellationToken)); } var key = CreateKey(identity); var contact = await _contactMap.GetValueOrDefaultAsync(key, cancellationToken); if (contact == null) { contact = await _contactExtension.GetAsync(identity, cancellationToken); await AddToCacheAsync(contact, key, cancellationToken); } return(contact); }