Hi All,
I created a CacheLoader
CacheLoader<CommutativePointPair,Double> cacheLoader = new CacheLoader<CommutativePointPair,Double>() {
public Double load(CommutativePointPair pp) {
return distance(new Point(pp.a1,pp.a2), new Point(pp.b1,pp.b2))
}
}
which I used to setup a LoadingCache
LoadingCache<CommutativePointPair,Double> cache = CacheBuilder.newBuilder().maximumSize(10000).build(cacheLoader);
The cache starts out empty and on the very first fetch from the cache (from within multi-threaded code)..
CommutativePointPair pointPair = new CommutativePointPair(p1,p2)
log.info("Entries in cache: ${distanceByPointsCache.size()}")
// returns Zero
cache.getUnchecked(pointPair)
I'm getting a NPE (Excerpt below)
java.lang.NullPointerException
at com.google.common.cache.LocalCache$Segment.drainKeyReferenceQueue(LocalCache.java:2549)
at com.google.common.cache.LocalCache$Segment.drainReferenceQueues(LocalCache.java:2538)
at com.google.common.cache.LocalCache$Segment.runLockedCleanup(LocalCache.java:3509)
at com.google.common.cache.LocalCache$Segment.preWriteCleanup(LocalCache.java:3490)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2257)
at com.google.common.cache.LocalCache.get(LocalCache.java:4000)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4004)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4874)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4880)
...
I noticed in the debugger that control goes to lockedGetOrLoad method because internal variable count is 0.
I've tried adding .expireAfterWrite(100, TimeUnit.MINUTES) to the cache-builder-configuration but it didn't make any difference.
Is there anything obvious that I am missing? I'm using guava14.0.1 (which was selected by code written previously).
Would greatly appreciate any help, pointers.
Thanks
Vish