java - invalidate refreshed entry in Guava CacheLoader -


i have guava cache cacheloader. there external condition track in thread, , if happens want refresh() entries asynchronously. reason not use invalidateall() since next get() have wait load succeed.

instead iterate on keys contained in cache , refresh(k) of them, not find refreshall() method. here code (but not related question):

    set<resourceloaderkey> keys = resourceloadercache.asmap().keyset();     for(resourceloaderkey k : keys)     {         resourceloadercache.refresh(k);     } 

my problem now, reload() in cacheloader might detect, resource not longer available. reload() throws resourcenotfound exception works get() case. not work refresh() case, old value served long reload() fails.

i can trap not-found exception in load/reload methods , invalidate entry somehow, wonder if there official way (returning null or null future logged warning , ignored)? able remove key/absent-value instead of keeping placeholder object around.

a supported way doesn't exist in guava r17.

have tried getting keys, invalidating all, attempting keys had saved?

set<resourceloaderkey> keys = resourceloadercache.asmap().keyset(); resourceloadercache.invalidateall(keys); for(resourceloaderkey k : keys) {     resourceloadercache.get(k);        //or getunchecked() whichever prefer } 

that should make sure no stale values stay in cache, , recache values exist.

(my problem different, had change assumptions solve mine)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -