public class SimpleCache<Key,Value> extends Object
SimpleCacheThe cache uses weak references to the keys but the values are strongly referenced. This leads to the conclusion, that the computed values should not refer to the keys because no cache entry will be reclaimend automatically. In such cases, clients have to discard the values for a key explicitly. Please note thatcache = new SimpleCache (new Function () { public V apply(K k) { // DON'T DO THIS if (k == k1) { return cache.get(k2).method(); } else if (k == k2) { return cache.get(k1).method(); } return null; } });
Function.apply(Object) may be invoked concurrently while the cache
itself is threadsafe.Copyright © 2015. All Rights Reserved.