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 longcapacity()voidclear()booleancontainsKey(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 weightedCapacityVget(K key)java.util.Iterator<K>hotKeyIterator(int n)booleanisEmpty()java.util.Iterator<K>keyIterator()voidput(K key, V value)booleanputIfAbsent(K key, V value)voidremove(K key)booleanreplace(K key, V old, V value)voidsetCapacity(long capacity)intsize()longweightedSize()
-
-
-
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:
setCapacityin interfaceCacheSize
-
isEmpty
public boolean isEmpty()
-
weightedSize
public long weightedSize()
- Specified by:
weightedSizein interfaceCacheSize
-
clear
public void clear()
- Specified by:
clearin interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
get
public V get(K key)
- Specified by:
getin interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
put
public void put(K key, V value)
- Specified by:
putin interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
putIfAbsent
public boolean putIfAbsent(K key, V value)
- Specified by:
putIfAbsentin interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
replace
public boolean replace(K key, V old, V value)
- Specified by:
replacein interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
remove
public void remove(K key)
- Specified by:
removein interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
keyIterator
public java.util.Iterator<K> keyIterator()
- Specified by:
keyIteratorin interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
hotKeyIterator
public java.util.Iterator<K> hotKeyIterator(int n)
- Specified by:
hotKeyIteratorin interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
containsKey
public boolean containsKey(K key)
- Specified by:
containsKeyin interfaceICache<K extends IMeasurableMemory,V extends IMeasurableMemory>
-
-