The question says it all I'd like to use CacheBuilder, but my values are pulled in asynchronously. This worked previously with MapMaker as the CacheLoader wasn't a requirement. Now I'd like to know if I can hack this up or if there are any non deprecated alternatives. Thank you.
I think the question you're trying to ask is "How can I use CacheBuilder without having to specify a CacheLoader?" If that's the case, then there will be support for this in Guava release 11.0. In the meantime a build() method on CacheLoader is already checked into trunk (as of this morning):
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilder.html
One method would be to make with generic parameters K and V as your desired outputs:
LoadingCache<K, ListenableFuture<V>> values = CacheBuilder.newBuilder()
.build(
new CacheLoader<K, ListenableFuture<V>>() {
public ListenableFuture<V> load(K key) {
/* Get your future */
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With