Class Async.AsyncWeigher<K,V>

java.lang.Object
com.github.benmanes.caffeine.cache.Async.AsyncWeigher<K,V>
All Implemented Interfaces:
Weigher<K,CompletableFuture<V>>, Serializable
Enclosing class:
Async

static final class Async.AsyncWeigher<K,V> extends Object implements Weigher<K,CompletableFuture<V>>, Serializable
A weigher for asynchronous computations. When the value is being loaded this weigher returns 0 to indicate that the entry should not be evicted due to a size constraint. If the value is computed successfully the entry must be reinserted so that the weight is updated and the expiration timeouts reflect the value once present. This can be done safely using Map.replace(Object, Object, Object).
  • Field Details

  • Constructor Details

    • AsyncWeigher

      AsyncWeigher(Weigher<K,V> delegate)
  • Method Details

    • weigh

      public int weigh(K key, CompletableFuture<V> future)
      Description copied from interface: Weigher
      Returns the weight of a cache entry. There is no unit for entry weights; rather they are simply relative to each other.
      Specified by:
      weigh in interface Weigher<K,V>
      Parameters:
      key - the key to weigh
      future - the value to weigh
      Returns:
      the weight of the entry; must be non-negative
    • writeReplace

      Object writeReplace()