code: public void addMessage(Message message) {
          synchronized (messages) {
              api.addMessageToCache(message);
              if (messages.stream().map(Reference::get).anyMatch(message::equals)) {
                  return;
              }
              // Add the message in the correct order
              messages.removeIf(messageRef -> messageRef.get() == null);
              Reference<Message> messageRef = new SoftReference<>(message, messagesCleanupQueue);
              int pos = Collections.binarySearch(messages, messageRef, Comparator.comparing(Reference::get));
              if (pos < 0) {
                  pos = -pos - 1;
              }
              messages.add(pos, messageRef);
          }
      }
docs: Adds a message to the cache.
  
  @param message The message to add.