--
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")
Certain cache configurations will result in the accrual of periodic maintenance tasks which will be performed during write operations, or during occasional read operations in the absence of writes. The Cache.cleanUp()
method of the returned cache will also perform maintenance, but calling it should not be necessary with a high throughput cache. Only caches built with removalListener, expireAfterWrite, expireAfterAccess, weakKeys, weakValues, or softValues perform periodic maintenance.
You don't need to call cleanup though, right? Even without calling it, cleanup operations will be performed eventually, I assume?
Currently automatic refreshes are performed when the first stale request for an entry occurs. The request triggering refresh will make a blocking call to
CacheLoader.reload(K, V)
and immediately return the new value if the returned future is complete, and the old value otherwise.
To ask more directly, it seems as though the refreshAfterWrite value causes the cache entry to be refreshed "after" a given amount of time, but that it is in fact triggered by a call to .get, as opposed to having a task scheduled to refresh the key when the countdown ends.
Which means that the next user to try to access that key will have to wait for the CacheLoader.load (which, in my case, is invariably a database call).
> Yeah, I see your pain. Unfortunately the benefit of adding something hereWhy add a new call rather than add to what cleanup does? After all
> may not outweigh the added api complexity.
you're already expecting cleanup to be slow. I mean let cleanup()
expiry entries and, if so configured, also trigger refreshes.
--
I wonder if we could make a structure that shares code and/or targets
these sorts of issues (ex. refresh on interval, cleanup before/after
use, etc). Here's some rough-in of Pool.
http://code.google.com/p/guava-libraries/issues/detail?id=683
-A
Cache<K, V> { Cache<K, Aged<V>> agedView(); }
Actually I wonder if "refresh" is the right semantic word to use, I'd
stick to something like "action" instead. Implemented properly, this
would enable for example a connection pool to leave an item in the map
but just send out a connection keep alive (a simple ping). I have a
feeling that we're closing in on something generic enough that will
add quite some rich functionality to the map.
Can someone suggest me to write a best practice Guava asynchronous
implementation for refresh. I have overwritten as
public ListenableFuture<List<User>> reload(final Integer key,
List<User> oldValue) throws Exception {
return ListenableFutureTask.create(new Runnable() {
@Override
public void run() {
cache.put(key,load(key));
}
},oldValue);
}
I am not sure I should have my own executorService for asynchronous
operations.