public class WeakCARCacheImpl<K,V> extends java.lang.Object implements WeakCARCache<K,V>
Modifier and Type | Class and Description |
---|---|
private static class |
WeakCARCacheImpl.CarValue<V> |
Modifier and Type | Field and Description |
---|---|
private WeakHashLRU<K> |
b1 |
private WeakHashLRU<K> |
b2 |
private Computable<K,V> |
computable |
private java.util.concurrent.atomic.AtomicLong |
hits |
private int |
maxSize |
private int |
p |
private WeakHashClock<K,WeakCARCacheImpl.CarValue<V>> |
t1 |
private WeakHashClock<K,WeakCARCacheImpl.CarValue<V>> |
t2 |
private java.util.concurrent.atomic.AtomicLong |
tries |
Constructor and Description |
---|
WeakCARCacheImpl(Computable<K,V> computable,
int maxSize,
boolean isWeak) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the current cache, making the current size zero
|
void |
clearStaleReferences()
Causes stale references to be cleared from the data
structures.
|
V |
compute(K key)
The method used to get or add values to this cache
|
java.lang.String |
dumpAllLists()
Returns a string that will contain all the elements of the four lists
|
int |
getB1Size()
Returns the number of items in the B1 LRU
|
int |
getB2Size()
Returns the number of items in the B2 LRU
|
Computable<K,V> |
getComputable()
The computable associated with this cache
|
double |
getHitRate()
Returns the hit rate from the last time clear was called
|
int |
getKeySize()
Returns the current number of keys in the cache.
|
int |
getMaxSize()
Gets the current maximum size of the cache (the maximum
number of values that will be kept by the cache).
|
int |
getP()
Returns the value of p from the CAR algorithm, which
is the target size of the t1 clock
|
int |
getT1Size()
Returns the number of items in the T1 clock
|
int |
getT2Size()
Returns the number of items in the T2 clock
|
private V |
getValueFromT(K key) |
int |
getValueSize()
Returns the current number of values in the cache.
|
void |
releaseMatching(CacheKeyFilter<K> filter)
Releases all key/value pairs that match the filter
|
boolean |
remove(K key)
Used to remove a single key and value from the cache (if
the value is available)
|
private void |
replace() |
java.lang.String |
toString() |
private final Computable<K,V> computable
private final int maxSize
private final WeakHashClock<K,WeakCARCacheImpl.CarValue<V>> t1
private final WeakHashClock<K,WeakCARCacheImpl.CarValue<V>> t2
private final WeakHashLRU<K> b1
private final WeakHashLRU<K> b2
private int p
private final java.util.concurrent.atomic.AtomicLong hits
private final java.util.concurrent.atomic.AtomicLong tries
public WeakCARCacheImpl(Computable<K,V> computable, int maxSize, boolean isWeak)
public V compute(K key)
WeakCARCache
compute
in interface WeakCARCache<K,V>
key
- The key to add to the cache. If the value
is not found, then the computable will be called to
get the value. May not be nullprivate void replace()
public int getKeySize()
WeakCARCache
getKeySize
in interface WeakCARCache<K,V>
public int getValueSize()
WeakCARCache
getValueSize
in interface WeakCARCache<K,V>
public void clear()
WeakCARCache
clear
in interface WeakCARCache<K,V>
public int getMaxSize()
WeakCARCache
getMaxSize
in interface WeakCARCache<K,V>
public Computable<K,V> getComputable()
WeakCARCache
getComputable
in interface WeakCARCache<K,V>
public boolean remove(K key)
WeakCARCache
remove
in interface WeakCARCache<K,V>
key
- The key to remove. May not be nullpublic void releaseMatching(CacheKeyFilter<K> filter)
WeakCARCache
releaseMatching
in interface WeakCARCache<K,V>
filter
- A non-null filter that can be used
to delete every key/value pair that matches the filterpublic void clearStaleReferences()
WeakCARCache
clearStaleReferences
in interface WeakCARCache<K,V>
public int getT1Size()
WeakCARCache
getT1Size
in interface WeakCARCache<K,V>
public int getT2Size()
WeakCARCache
getT2Size
in interface WeakCARCache<K,V>
public int getB1Size()
WeakCARCache
getB1Size
in interface WeakCARCache<K,V>
public int getB2Size()
WeakCARCache
getB2Size
in interface WeakCARCache<K,V>
public int getP()
WeakCARCache
getP
in interface WeakCARCache<K,V>
public java.lang.String dumpAllLists()
WeakCARCache
dumpAllLists
in interface WeakCARCache<K,V>
public double getHitRate()
WeakCARCache
getHitRate
in interface WeakCARCache<K,V>
public java.lang.String toString()
toString
in class java.lang.Object