Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guava LoadingCache getAll - but without any arguments?

I am using Guava LoadingCache to bulk load all elements at once into my eager cache. But the implementation of the loadAll method that I'm supplying does not really need an Iterable<? extends K> keys argument, since my DAO does not except any parameters either - my DAO method returns generic Map<K,V>.

Since my implementation is generic, I'm using generics to do a call on getAllIterable(<? extends K> keys_), but because of the type erasure, I can not instantiate K key, and pass it to getAll, since it does not expect any non null keys.

Does anyone know of any workaround around this?

like image 487
GMoney Avatar asked Dec 04 '25 05:12

GMoney


1 Answers

If the goal is just to prepopulate a Cache with the contents of a Map<K, V>, then you should just use Cache.putAll(Map<K, V>) to put all the entries from a specified Map in the cache.

like image 121
Louis Wasserman Avatar answered Dec 05 '25 21:12

Louis Wasserman