@ThreadSafe
public class WindowTinyLFUMap<K,V>
extends java.util.AbstractMap<K,V>
implements java.io.Serializable
the weak-key cache applies to scenarios where objects can be collected. when memory lock causes full gc, the weakKey will collect by gc.
the strong-key cache applies to immutable cache object data, and the user determines the cache size.
about the weak-key cache and strong-key cache, please refer to: caffeine cache ISSUES #776
| Constructor and Description |
|---|
WindowTinyLFUMap(int initialCapacity,
long maximumSize,
java.lang.Boolean weakKey)
initial caffeine cache include WeakReference cache and StrongReference cache.
|
WindowTinyLFUMap(int initialSize,
long expireAfterWrite,
long maximumSize,
java.lang.Boolean weakKey) |
WindowTinyLFUMap(long maximumSize)
build caffeine cache.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
V |
get(java.lang.Object key) |
V |
put(K key,
V value) |
V |
remove(java.lang.Object key) |
int |
size() |
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, valuespublic WindowTinyLFUMap(long maximumSize)
maximumSize - maximumSizepublic WindowTinyLFUMap(int initialCapacity,
long maximumSize,
java.lang.Boolean weakKey)
when the weakKey is true that means using weakKeys cache, gc will collect the weak key, please refer to: com.github.benmanes.caffeine.cache.References.WeakKeyReference
when the weakKey is false, use strong reference, jvm maybe throw oom-error.
Map<String, Object> strongMap = new WindowTinyLFUMap<>(100, 100, Boolean.FALSE);
strongMap.put(new String("abc"), 1);
strongMap.put(new String("abc"), 1);
assert strongMap.get("abc") != null;
Map<String, Object> strongMap = new WindowTinyLFUMap<>(100, 100, Boolean.TRUE);
strongMap.put(new String("abc"), 1);
strongMap.put(new String("abc"), 1);
assert strongMap.get("abc") == null;
initialCapacity - initial capacitymaximumSize - maximum sizeweakKey - weak keypublic WindowTinyLFUMap(int initialSize,
long expireAfterWrite,
long maximumSize,
java.lang.Boolean weakKey)
Copyright © 2024 The Apache Software Foundation. All rights reserved.