I am doing cache of images for faster downloading from network share and/or internet. Currently, this cache is in memory.
Is it possible to limit cache by deep size of objects (prelimilarly of BufferedImageSize
)?
Cache is initialized like following
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
....
imageCache = CacheBuilder.newBuilder()
.maximumSize(cacheSize)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build(
new CacheLoader<String, DeferredImage>() {
public DeferredImage load(String pathname) throws IOException {
return new DeferredImage(pathname);
}
});
Where DeferredImage
is a wrapper around BufferedImage
to facilitate loading in separate thread.
Is it possible to code some size checking, which takes into account not number of entries in cache, but their size in bytes?
UPDATE
I found maximumWeight() method but didn't understand if this what I am looking for: documentation nowhere states, that the sum of weights is calculated.