K
- type of the keyV
- type of the valuepublic class LruKCache<K,V> extends AbstractCache<K,V>
Cache
that uses the LRU-K algorithm as an eviction policy.DEFAULT_CAPACITY
Constructor and Description |
---|
LruKCache()
Constructor for the LruKCache object.
|
LruKCache(int capacity,
int historyCapacity,
int numberOfIds)
Constructor for the LruKCache object.
|
LruKCache(Resolver<K,V> resolver)
Constructor for the LruKCache object.
|
LruKCache(Resolver<K,V> resolver,
int capacity)
Constructor for the LruKCache object.
|
LruKCache(Resolver<K,V> resolver,
int capacity,
int historyCapacity,
int numberOfIds)
Constructor for the LruKCache object.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all key-value mappings from the cache and cleans the history queue.
|
boolean |
containsKey(K key)
Checks whether the specified key is cached.
|
void |
evict()
Removes the key with the highest backward-K-distance.
|
V |
get(K key)
Gets the value associated with the specified key from the cache if a mapping exists, or the value returned by the resolver.
|
int |
historyCapacity()
Returns the maximum capacity of the history queue.
|
Set<K> |
keySet()
Gets all keys contained in the cache.
|
K |
nextEvicted()
Gets the key with the highest backward-K-distance.
|
int |
numberOfIds()
Returns the number of id's the LRU-K algorithm uses.
|
V |
put(K key,
V value)
Adds a new key-value mapping to the cache.
|
V |
remove(K key)
Removes the specified key and its value from the cache.
|
int |
size()
Returns the number of key-value mappings in the cache.
|
String |
toString()
Returns a text representation of the cache.
|
V |
update(K key,
V value)
Updates the value associated with the specified key in the cache if a mapping exists for the key.
|
capacity, getResolver, hitRatio, hits, misses, requests, resetCounters, setResolver
public LruKCache()
public LruKCache(Resolver<K,V> resolver)
resolver
- resolver to associate with the cachepublic LruKCache(int capacity, int historyCapacity, int numberOfIds)
capacity
- capacity of the cachehistoryCapacity
- capacity of the history queuenumberOfIds
- number of id's the LRU-K algorithm should usepublic LruKCache(Resolver<K,V> resolver, int capacity)
resolver
- resolver to associate with the cachecapacity
- capacity of the cachepublic LruKCache(Resolver<K,V> resolver, int capacity, int historyCapacity, int numberOfIds) throws IllegalArgumentException
resolver
- resolver to associate with the cachecapacity
- capacity of the cachehistoryCapacity
- capacity of the history queuenumberOfIds
- number of id's the LRU-K algorithm should useIllegalArgumentException
- when history capacity is smaller or equal to zeropublic V put(K key, V value)
public V get(K key)
public V update(K key, V value)
public boolean containsKey(K key)
containsKey
in interface Cache<K,V>
containsKey
in class AbstractCache<K,V>
key
- key to checkpublic void clear()
public Set<K> keySet()
Set
of keys contained in the cache.public int size()
public K nextEvicted()
nextEvicted
in interface Cache<K,V>
nextEvicted
in class AbstractCache<K,V>
public void evict()
public int numberOfIds()
public int historyCapacity()
public String toString()
toString
in class AbstractCache<K,V>
Copyright © 2016 Egothor. All Rights Reserved.