- try (final var connection = database.getConnection()) {
- connection.setAutoCommit(false);
- storeContact(connection, recipientId, null);
- storeProfile(connection, recipientId, null);
- storeProfileKey(connection, recipientId, null, false);
- storeExpiringProfileKeyCredential(connection, recipientId, null);
- deleteRecipient(connection, recipientId);
- connection.commit();
- } catch (SQLException e) {
- throw new RuntimeException("Failed update recipient store", e);
+ synchronized (recipientsLock) {
+ recipientAddressCache.entrySet()
+ .stream()
+ .filter(e -> e.getValue().id().equals(recipientId))
+ .forEach(e -> recipientAddressCache.remove(e.getKey()));
+ try (final var connection = database.getConnection()) {
+ connection.setAutoCommit(false);
+ storeContact(connection, recipientId, null);
+ storeProfile(connection, recipientId, null);
+ storeProfileKey(connection, recipientId, null, false);
+ storeExpiringProfileKeyCredential(connection, recipientId, null);
+ deleteRecipient(connection, recipientId);
+ connection.commit();
+ } catch (SQLException e) {
+ throw new RuntimeException("Failed update recipient store", e);
+ }