I have strange (at least for me) behavior with guava cache. After the first click, the following calls return an empty object. I have not used the strange extinction, so I can not understand where I am doing wrong. I declared the following LoadingCache:
LoadingCache<String, Vector<Location>> locations = CacheBuilder.newBuilder()
.maximumSize(100000)
.build(
new CacheLoader<String,Vector<Location>>() {
@Override
public Vector<Location> load(String key) {
return _getLocationListByTranscriptId(key);
}
});
and I used it only in this method:
public Vector<Location> getLocationListByTranscriptId (String transcriptid) {
if (transcriptid.equals("TCONS_00000046")) System.out.println("tcons found, will this work?");
Vector<Location> result;
try {
result = locations.get(transcriptid);
} catch (ExecutionException e) {
System.err.println("Error accessing cache, doing the hard way");
result = _getLocationListByTranscriptId(transcriptid);
}
if (transcriptid.equals("TCONS_00000046")){
if (result.size()==0){
System.out.println("this is a problem");
return null;
}
System.out.println("this is good!");
}
return result;
}
Iterating over the collection of input string, I get the following output:
tcons found, will this work?
this is good!
tcons found, will this work?
this is a problem
So, the first time I use the cache, it works, but A) the value is not correctly stored for future calls; B) the value is reset for some strange behavior. What can I do? Thanks everyone for that!
EDIT:
axtavt , . , , , guava . . (, ).