public class LongKeyLruCache<V>
extends java.lang.Object
LongKeyLruCache is synchronized.
Constructor and Description |
---|
LongKeyLruCache(int initialCapacity)
Create the LRU cache with a specific capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the cache
|
LongKeyLruCache<V> |
ensureCapacity(int newCapacity)
Ensure the cache can contain the given value.
|
V |
get(long key)
Get an item from the cache and make it most recently used.
|
int |
getCapacity()
Returns the capacity.
|
long |
getHitCount()
Returns the hit count.
|
long |
getMissCount()
Returns the miss count.
|
V |
put(long key,
V value)
Puts a new item in the cache.
|
V |
putIfAbsent(long key,
V value)
Puts a new item in the cache.
|
V |
putIfNew(long key,
V value)
Puts a new item in the cache.
|
V |
remove(long key)
Removes an item from the cache
|
boolean |
removeTail()
Remove the last item in the LRU
|
LongKeyLruCache<V> |
setCapacity(int newCapacity) |
int |
size()
Returns the current number of entries in the cache.
|
java.util.Iterator<V> |
values()
Returns the values in the cache
|
java.util.Iterator<V> |
values(java.util.Iterator<V> oldIter) |
public LongKeyLruCache(int initialCapacity)
initialCapacity
- minimum capacity of the cachepublic int size()
public int getCapacity()
public LongKeyLruCache<V> ensureCapacity(int newCapacity)
public LongKeyLruCache<V> setCapacity(int newCapacity)
public void clear()
public V get(long key)
key
- key to lookup the itempublic V put(long key, V value)
key
- key to store datavalue
- value to be storedpublic V putIfNew(long key, V value)
key
- key to store datavalue
- value to be storedpublic V putIfAbsent(long key, V value)
key
- key to store datavalue
- value to be storedpublic boolean removeTail()
public V remove(long key)
key
- the key to removepublic java.util.Iterator<V> values()
public long getHitCount()
public long getMissCount()