com.caucho.util
Class ClockCache<K,E extends ClockCacheItem>

java.lang.Object
  extended by com.caucho.util.ClockCache<K,E>

public class ClockCache<K,E extends ClockCacheItem>
extends java.lang.Object

Cache with a clock replacement policy.

Null keys are not allowed. LruCache is synchronized.


Constructor Summary
ClockCache(int initialCapacity)
          Create the clock cache with a specific capacity.
 
Method Summary
 void clear()
          Clears the cache
 E get(K key)
          Get an item from the cache and make it most recently used.
 E put(K key, E value)
          Puts a new item in the cache.
 ClockCacheItem remove(K key)
          Removes an item from the cache
 int size()
          Returns the current number of entries in the cache.
 java.util.Iterator<E> values()
          Returns the values in the cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClockCache

public ClockCache(int initialCapacity)
Create the clock 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.


clear

public void clear()
Clears the cache


get

public E get(K 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 E put(K key,
             E 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

remove

public ClockCacheItem remove(K key)
Removes an item from the cache

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

values

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