--tim--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
--tim--
This is very interesting, and I'm glad to see it written up so clearly! I could easily get behind adding something like com.google.common.cache.CacheLoaders.loadAllInParallel(CacheLoader<K, V>, Executor) which turned the sequential calls into parallel calls. Would that be enough for you?
It ends up that we already have an internal CacheLoaders.asyncReload(CacheLoader<K, V>, Executor), and this seems like a good fit to go right along side it.
I don't see either of these being core enough for deeper integration, but I'm in favor of supporting common but simple CacheLoader extensions in a CacheLoaders class.
--
Nice! Yes, I think that would work. In which case, no need for CacheLoaders.loadAllInParall, just add static CacheLoader.from(AsyncFunction<K, V>) I'll recast what I've done in those terms. For my Hazelcast case, I've just now written an AsyncFunction implementation and a static factory method that converts a Function and a (Hazelcast) Executor to an instance of that AsyncFunction impl.
That keeps the Hazelcast-specific stuff neatly stowed away.
Is there a static method that takes an AsyncFunction and an Iterable of keys and produces a Map of keys to values? I'll want to write one if not.
--tim
ListenableFuture<V>
loadFuture(
K
key) throws
Exception;
ListenableFuture<V>
refresh(
K
key) throws
Exception;
Map<K, ListenableFuture<V>> loadAllFutures(Iterable<? extends K> keys) throws Exception;
LoadingCache
methods we need are:Future<V> getFuture(K key);
void refresh(K key);
ImmutableMap<K, Future<V>> getAllFutures(Iterable<? extends K> keys);
Cache
methods are a little more tricky. On the one hand, most of them are less obviously asynchronous. On the other hand, other Cache implementations might need to accomodate asynchronous errors even from void methods. The simplest methods are these ones:void cleanUp();
ListenableFuture<V> getFuture(K key, Callable<? extends V> valueLoader);
ImmutableMap<K, V> getAllPresent(Iterable<? extends K> keys);
V getIfPresent(K key);
long size();
CacheStats stats();
Future<Void>
to return errors?asMap()
view do? Expose V
or Future<V>
?CacheLoader
and AsyncCacheLoader
, and between LoadingCache
and AsyncLoadingCache
?But I don't see what AsyncCacheLoader and AsyncLoadingCache add to the picture.
Note that the advantage of going the AsyncCacheLoader route instead of just adding CacheLoader.from(AsyncFunction<K, V>) is that it facilitates the selective over-riding of reload or loadAll.
I left the AsyncCacheLoader stuff out, because I'm missing the use cases.
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
-A