Package org.apache.cassandra.cache
Class CaffeineCache<K extends IMeasurableMemory,V extends IMeasurableMemory>
- java.lang.Object
-
- org.apache.cassandra.cache.CaffeineCache<K,V>
-
public class CaffeineCache<K extends IMeasurableMemory,V extends IMeasurableMemory> extends java.lang.Object implements ICache<K,V>
An adapter from a Caffeine cache to the ICache interface. This provides an on-heap cache using the W-TinyLFU eviction policy (http://arxiv.org/pdf/1512.00727.pdf), which has a higher hit rate than an LRU.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description long
capacity()
void
clear()
boolean
containsKey(K key)
static <K extends IMeasurableMemory,V extends IMeasurableMemory>
CaffeineCache<K,V>create(long weightedCapacity)
static <K extends IMeasurableMemory,V extends IMeasurableMemory>
CaffeineCache<K,V>create(long weightedCapacity, com.github.benmanes.caffeine.cache.Weigher<K,V> weigher)
Initialize a cache with initial capacity with weightedCapacityV
get(K key)
java.util.Iterator<K>
hotKeyIterator(int n)
boolean
isEmpty()
java.util.Iterator<K>
keyIterator()
void
put(K key, V value)
boolean
putIfAbsent(K key, V value)
void
remove(K key)
boolean
replace(K key, V old, V value)
void
setCapacity(long capacity)
int
size()
long
weightedSize()
-
-
-
Method Detail
-
create
public static <K extends IMeasurableMemory,V extends IMeasurableMemory> CaffeineCache<K,V> create(long weightedCapacity, com.github.benmanes.caffeine.cache.Weigher<K,V> weigher)
Initialize a cache with initial capacity with weightedCapacity
-
create
public static <K extends IMeasurableMemory,V extends IMeasurableMemory> CaffeineCache<K,V> create(long weightedCapacity)
-
setCapacity
public void setCapacity(long capacity)
- Specified by:
setCapacity
in interfaceCacheSize
-
isEmpty
public boolean isEmpty()
-
weightedSize
public long weightedSize()
- Specified by:
weightedSize
in interfaceCacheSize
-
clear
public void clear()
- Specified by:
clear
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
get
public V get(K key)
- Specified by:
get
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
put
public void put(K key, V value)
- Specified by:
put
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
putIfAbsent
public boolean putIfAbsent(K key, V value)
- Specified by:
putIfAbsent
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
replace
public boolean replace(K key, V old, V value)
- Specified by:
replace
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
remove
public void remove(K key)
- Specified by:
remove
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
keyIterator
public java.util.Iterator<K> keyIterator()
- Specified by:
keyIterator
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
hotKeyIterator
public java.util.Iterator<K> hotKeyIterator(int n)
- Specified by:
hotKeyIterator
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
containsKey
public boolean containsKey(K key)
- Specified by:
containsKey
in interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
-