I have a question. If I use expireAfterAccess and suppose my entry gets expired after 2 hours. Now if I call get() for that entry after some time (say 5 hours), will it get cached again? or will it expire for good?
private final LoadingCache<String, Map<String, PinPointRule>> pinPointRuleCache = CacheBuilder.newBuilder().maximumSize(500000)
.expireAfterAccess(2, TimeUnit.HOURS).build(new CacheLoader<String, Map<String, PinPointRule>>(){
@Override
public Map<String, PinPointRule> load(String dummyToken) throws Exception {
return loadPinPointRules(dummyToken);
}
public ListenableFuture<Map<String,PinPointRule>> reload(final String key, final Map<String,PinPointRule> oldValue) throws Exception {
ListenableFutureTask<Map<String,PinPointRule>> task = ListenableFutureTask.create(new Callable<Map<String,PinPointRule>>() {
public Map<String,PinPointRule> call() throws Exception {
long start = System.nanoTime();
LOGGER.info("LoadingCache Reload");
try {
return loadPinPointRules(key);
} catch (Exception e) {
LOGGER.error("Error while loading pinpoint rules. Returning old value. Exception :: {}", getStackTrace(e));
} finally {
LOGGER.info("Time taken in reloading pinpoint rule: {} ", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
}
return oldValue;
}
});
executor.execute(task);
return task;
};
});