jhalterman / expiringmap

A high performance thread-safe map that expires entries
Apache License 2.0
1k stars 142 forks source link

Can expiringmap provide a function to obtain multiple keys? #86

Open wp973 opened 8 months ago

wp973 commented 8 months ago

like caffeine getAllPresent

 Map<K, V> getAllPresent(Iterable<? extends K> keys)

I tried to write a method, is this method feasible?🤔

  public List<V> getAllPresent(List<K> keys) {

    List<V> result = Collections.emptyList();

    if (keys != null && !keys.isEmpty()) {
      result = new ArrayList<V>(keys.size());

      for (K key : keys) {
        V value = get(key);

        if (value != null) {
          result.add(get(key));
        }
      }

    }

    return result;
  }

Thanks for your reply.