shz.cache.LocalCache Maven / Gradle / Ivy
package shz.cache;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public abstract class LocalCache implements Cache {
private final RefType refType;
protected ReferenceQueue super V> queue;
protected LocalCache(RefType refType, ReferenceQueue super V> queue) {
this.refType = refType;
this.queue = queue;
}
protected final Reference getReference(V val) {
return refType == RefType.WEAK ? new WeakReference<>(val, queue) : new SoftReference<>(val, queue);
}
public static final ConcurrentMap> CACHE = new ConcurrentHashMap<>();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy