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
Post a Comment