I have a Java class with Guava LoadingCache<String, Integer>, and I plan to store two things in this cache: the average time of active employees was working for a day and efficiency. I cache these values because it would be expensive to compute every time a request arrives. In addition, the contents of the cache will be updated ( refreshAfterWrite) every minute.
I was thinking of using CacheLoaderfor this situation, however its load method loads only one value per key. In mine, CacheLoaderI planned to do something like:
private Service service = new Service();
public Integer load(String key) throws Exception {
if (key.equals("employeeAvg"))
return calculateEmployeeAvg(service.getAllEmployees());
if (key.equals("employeeEff"))
return calculateEmployeeEff(service.getAllEmployees());
return -1;
}
, service.getAllEmployees(), , , , CacheLoader .
LoadingCache.put(key, value), , service.getAllEmployees() " ". , LoadingCache.put(), refreshAfterWrite, .
?