  @SuppressWarnings({"FutureReturnValueIgnored", "ResultOfMethodCallIgnored"})
  default void handleCompletion(K key, CompletableFuture<? extends V> valueFuture,
      long startTime, boolean recordMiss) {
    valueFuture.whenComplete((value, error) -> {
      long loadTime = cache().statsTicker().read() - startTime;
      if (value == null) {
        if ((error != null) && !(error instanceof CancellationException)
            && !(error instanceof TimeoutException)) {
          logger.log(Level.WARNING, "Exception thrown during asynchronous load", error);
        }
        cache().statsCounter().recordLoadFailure(loadTime);
        cache().remove(key, valueFuture);
      } else if (!Async.isReady(valueFuture)) {
        logger.log(Level.ERROR, String.format(US, "An invalid state was detected, occurring when "
            + "the future's dependent action has completed successfully with a value, but the "
            + "future remains either in-flight or in a failed completion state. This may occur "
            + "when using a custom future that does not abide by the CompletableFuture contract "
            + "(key: %s, key type: %s, value type: %s, future: %s, cache type: %s).",
            key, key.getClass().getName(), value.getClass().getName(), valueFuture,
            cache().getClass().getSimpleName()), new IllegalStateException());
        cache().statsCounter().recordLoadFailure(loadTime);
        cache().remove(key, valueFuture);
      } else {
        @SuppressWarnings("unchecked")
        var castedFuture = (CompletableFuture<V>) valueFuture;

        try {
          // update the weight and expiration timestamps
          cache().replace(key, castedFuture, castedFuture, /* shouldDiscardRefresh= */ false);
          cache().statsCounter().recordLoadSuccess(loadTime);
        } catch (Throwable t) {
          logger.log(Level.WARNING, "Exception thrown during asynchronous load", t);
          cache().statsCounter().recordLoadFailure(loadTime);
          cache().remove(key, valueFuture);
        }
