J'ai une question. Si j'utilise expireAfterAccess et suppose que mon entrée expire après 2 heures. Maintenant, si j'appelle get() pour cette entrée après un certain temps (disons 5 heures), sera-t-il à nouveau mis en cache? ou va-t-il expirer pour de bon?Goyave cache expireAfterAccess question
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;
};
});
Il sera à nouveau mis en cache (c'est-à-dire que la méthode 'load' sur' CacheLoader' que vous aurez fourni sera appelée), c'est comme ça que fonctionnent les caches. – Xaerxess
@Xaerxess: merci, je n'ai pas pu obtenir cette information par le biais du document. – Boola