I am using Guava to handle caching in my web application; I want to auto refresh the existing elements in my cache every 10 minutes.
this is my snippet code:
private Cache<String, Integer> cache = CacheBuilder.newBuilder.build();
//my main method
public Integer load(String key){
Integer value = cache.getIfPresent(key)
if(value == null){
value = getKeyFromServer(key);
//insert in my cache
cache.put(key, value);
}
return value;
}
I want to enhance the above code in order to refresh the elements gathered in my cache map as bellow:
//1. iterate over cache map
for(e in cache){
//2. get new element value from the server
value = getKeyFromServer(e.getKey());
//3. update the cache
cache.put(key, value);
}