com.caucho.util
Class LongKeyLruCache<V>

java.lang.Object
  extended by com.caucho.util.LongKeyLruCache<V>

public class LongKeyLruCache<V>
extends java.lang.Object

Fixed length cache with a LRU replacement policy. If cache items implement CacheListener, they will be informed when they're removed from the cache.

LongKeyLruCache is synchronized.


Constructor Summary
LongKeyLruCache(int initialCapacity)
          Create the LRU cache with a specific capacity.
 
Method Summary
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LongKeyLruCache

public LongKeyLruCache(int initialCapacity)
Create the LRU cache with a specific capacity.

Parameters:
initialCapacity - minimum capacity of the cache
Method Detail

size

public int size()
Returns the current number of entries in the cache.


getCapacity

public int getCapacity()
Returns the capacity.


ensureCapacity

public LongKeyLruCache<V> ensureCapacity(int newCapacity)
Ensure the cache can contain the given value.


setCapacity

public LongKeyLruCache<V> setCapacity(int newCapacity)

clear

public void clear()
Clears the cache


get

public V get(long key)
Get an item from the cache and make it most recently used.

Parameters:
key - key to lookup the item
Returns:
the matching object in the cache

put

public V put(long key,
             V value)
Puts a new item in the cache. If the cache is full, remove the LRU item.

Parameters:
key - key to store data
value - value to be stored
Returns:
old value stored under the key

putIfNew

public V putIfNew(long key,
                  V value)
Puts a new item in the cache. If the cache is full, remove the LRU item.

Parameters:
key - key to store data
value - value to be stored
Returns:
the value actually stored

putIfAbsent

public V putIfAbsent(long key,
                     V value)
Puts a new item in the cache. If the cache is full, remove the LRU item.

Parameters:
key - key to store data
value - value to be stored
Returns:
the value actually stored

removeTail

public boolean removeTail()
Remove the last item in the LRU


remove

public V remove(long key)
Removes an item from the cache

Parameters:
key - the key to remove
Returns:
the value removed

values

public java.util.Iterator<V> values()
Returns the values in the cache


values

public java.util.Iterator<V> values(java.util.Iterator<V> oldIter)

getHitCount

public long getHitCount()
Returns the hit count.


getMissCount

public long getMissCount()
Returns the miss count.