com.continuent.tungsten.common.cache
Class IndexedLRUCache<T>

java.lang.Object
  extended by com.continuent.tungsten.common.cache.IndexedLRUCache<T>

public class IndexedLRUCache<T>
extends java.lang.Object

Implements a self-managing cache suitable for database metadata. The cache has a specific capacity which is maintained by invalidating cache nodes implicitly using an LRU (least recently used) algorithm. Clients can also invalidate individual keys, key ranges, and the entire cache.

NOTE: The cache is designed for use by a single thread. There is no synchronization, nor do we have a notion of "loans."

Author:
Robert Hodges

Constructor Summary
IndexedLRUCache(int capacity, CacheResourceManager<T> resourceManager)
          Creates a new prepared statement cache.
 
Method Summary
 T get(java.lang.String key)
          Retrieves a value or returns null if it is not in the cache.
 int invalidate(java.lang.String key)
          Release the value corresponding to a specific key, returning the number of items deleted.
 int invalidateAll()
          Invalidate all values in the cache, returning number of items deleted.
 int invalidateByPrefix(java.lang.String prefix)
          Invalidate all values that start with the given key prefix, returning number deleted.
 java.util.Set<java.lang.String> keys()
          Returns all current keys.
 java.util.List<T> lruValues()
          Returns values in LRU order.
 void put(java.lang.String key, T value)
          Store a value in the cache.
 int size()
          Return current size of list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexedLRUCache

public IndexedLRUCache(int capacity,
                       CacheResourceManager<T> resourceManager)
Creates a new prepared statement cache.

Parameters:
capacity - Maximum capacity of the cache, after which nodes are removed in LRU order
resourceManager - Name of the cache manager
Method Detail

size

public int size()
Return current size of list.


put

public void put(java.lang.String key,
                T value)
Store a value in the cache.


get

public T get(java.lang.String key)
Retrieves a value or returns null if it is not in the cache.


keys

public java.util.Set<java.lang.String> keys()
Returns all current keys.


lruValues

public java.util.List<T> lruValues()
Returns values in LRU order.


invalidateAll

public int invalidateAll()
Invalidate all values in the cache, returning number of items deleted.


invalidateByPrefix

public int invalidateByPrefix(java.lang.String prefix)
Invalidate all values that start with the given key prefix, returning number deleted.


invalidate

public int invalidate(java.lang.String key)
Release the value corresponding to a specific key, returning the number of items deleted.