CacheLoader asyncReloading

1,865 views
Skip to first unread message

micha...@gmail.com

unread,
Jul 9, 2014, 3:16:55 PM7/9/14
to guava-...@googlegroups.com
Is there any code example that is using the method CacheLoader.asyncReloading, to be used for asynchronous loading/refreshing for cache entries.

Basically, I want to use CacheBuilder along with the CacheLoader to load entries to the cache asynchronously without blocking, then at the time of successful load/refresh, I want to do some logic in the callback.

Here is a code I'm using, http://pastebin.com/bwG6eZ7F , The problem is that the 4 sequential calls

  1. cache.refresh("x1");
  2. cache.refresh("x2");
  3. cache.refresh("x3");
  4. cache.refresh("x4");

are blocking.

I'm using Guava 17.0, Java 7

Thanks in advance.

Louis Wasserman

unread,
Jul 9, 2014, 4:05:22 PM7/9/14
to micha...@gmail.com, guava-...@googlegroups.com
The issue here is that you're calling refresh on an empty cache.  CacheLoader.reload gets called when there's a preexisting entry for the key being requested, but the normal CacheLoader.load has to get called if the key wasn't already in the cache.


--
--
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?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/702bde19-58b5-46dc-bb75-5bb7605e152f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Louis Wasserman

micha...@gmail.com

unread,
Jul 9, 2014, 4:50:19 PM7/9/14
to guava-...@googlegroups.com, micha...@gmail.com
Ok. That's the case for refreshing, but, how to load values in the cache asynchronously, and after successful loading invoke logic on the value in a callback.

Louis Wasserman

unread,
Jul 9, 2014, 4:52:08 PM7/9/14
to micha...@gmail.com, guava-...@googlegroups.com
I think the honest answer has to be to do the asynchronous loading yourself: submit a task to an Executor that calls cache.load.



For more options, visit https://groups.google.com/d/optout.



--
Louis Wasserman
Reply all
Reply to author
Forward
0 new messages