I suggest using imcache and loading the necessary elements from disk using the cache loader as follows:
Cache<String,Object> yourCache = CacheBuilder.
concurrentHeapCache().cacheLoader(new CacheLoader<String, Object>() {
public Object load(String key) {
//code to load item from file.
}
}).build();
source
share