The following code shows then it will work
private static final LoadingCache<String, Map<Integer, AtomicLong>> NWZs = CacheBuilder.newBuilder()
.weakKeys()
.weakValues()
.expireAfterWrite(60, TimeUnit.MINUTES)
.expireAfterAccess(20, TimeUnit.MINUTES)
.build(
new CacheLoader<String, Map<Integer, AtomicLong>>() {
@Override
public Map<Integer, AtomicLong> load(String word) throws Exception {
Map<Integer, AtomicLong> map = new HashMap<>();
map.put(0, new AtomicLong(10));
return map;
}
});
public static void main(String[] args) throws Exception {
System.out.println(NWZs.get("foo").get(0));
Map<Integer, AtomicLong> wincm = NWZs.get("foo");
wincm.get(0).addAndGet(5);
System.out.println(NWZs.get("foo").get(0));
}
The output should be
10
15