public Map < K , V > getAll ( Iterable < K > keys ) { List < K > missingKeys = new ArrayList <> ( ) ; Map < K , V > result = new HashMap <> ( ) ; for ( K key : keys ) { V value = map . get ( key ) ; if ( value == null && ! map . containsKey ( key ) ) { missingKeys . add ( key ) ; } else { result . put ( key , value ) ; } } if ( ! missingKeys . isEmpty ( ) ) { Map < K , V > missingValues = loader . loadAll ( missingKeys ) ; map . putAll ( missingValues ) ; result . putAll ( missingValues ) ; for ( K missingKey : missingKeys ) { if ( ! map . containsKey ( missingKey ) ) { map . put ( missingKey , null ) ; result . put ( missingKey , null ) ; } } } return result ; }
Get values associated with keys . All the requested keys are included in the Map result . Value is null if the key is not found in cache .