org.exolab.castor.persist

Class LRU

Known Direct Subclasses:
LRU.CountLimited, LRU.NoCache, LRU.TimeLimited, LRU.Unlimited

public abstract class LRU
extends java.lang.Object

Base interface for all least-recently-used cache.
Author:
Thomas Yip

Nested Class Summary

static class
LRU.CountLimited
CountLimited is a count limted least-recently-used Map.
static class
LRU.NoCache
NoCache is a Map which dispose all object right the way.
static class
LRU.TimeLimited
TimeLimited is a time limted least-recently-used Map.
static class
LRU.Unlimited
UnLimited is Map which implements the LRU interface.

Field Summary

static int
CACHE_COUNT_LIMITED
Map type of Count-Limited least-recently-used as caching mechanism.
static int
CACHE_NONE
Map type for no caching as the caching mechanism.
static int
CACHE_TIME_LIMITED
Map type of Time-Limited least-recently-used is used as caching mechanism.
static int
CACHE_UNLIMITED
Map type of unlimited cache as caching mechanism.
static int
DEFAULT_PARAM
Specify the default LRU parameter
static int
DEFAULT_TYPE
Specify the default LRU mechanism

Method Summary

static LRU
create(int type, int param)
Factory method to create a LRU map of specified type.
abstract Enumeration
elements()
Returns an enumeration of the values in this LRU map.
abstract Object
get(Object key)
Returns the value to which the specified key is mapped in this hashtable.
static int
mapType(String type)
Map the type in String into an int to represent the lru cache type.
abstract Object
put(Object key, Object value)
Maps the specified key to the specified value in this hashtable.
abstract Object
remove(Object key)
Removes the key (and its corresponding value) from this hashtable.

Field Details

CACHE_COUNT_LIMITED

public static final int CACHE_COUNT_LIMITED
Map type of Count-Limited least-recently-used as caching mechanism. Object Lock which is not hold by any transcation will be put in the cache, until the cache is full and other object overwritten it.
Field Value:
2

CACHE_NONE

public static final int CACHE_NONE
Map type for no caching as the caching mechanism. All object put into the map will be discarded.
Field Value:
1

CACHE_TIME_LIMITED

public static final int CACHE_TIME_LIMITED
Map type of Time-Limited least-recently-used is used as caching mechanism. Object Lock which is not hold by any transcation will be put in the cache, until timeout is reached.
Field Value:
3

CACHE_UNLIMITED

public static final int CACHE_UNLIMITED
Map type of unlimited cache as caching mechanism. Object Lock which is not hold by any transcation will be put in the cache for later use.
Field Value:
4

DEFAULT_PARAM

public static final int DEFAULT_PARAM
Specify the default LRU parameter
Field Value:
100

DEFAULT_TYPE

public static final int DEFAULT_TYPE
Specify the default LRU mechanism
Field Value:
2

Method Details

create

public static LRU create(int type,
                         int param)
Factory method to create a LRU map of specified type.
Parameters:
type - mechanism type
param - capacity of the lru

elements

public abstract Enumeration elements()
Returns an enumeration of the values in this LRU map. Use the Enumeration methods on the returned object to fetch the elements sequentially.
Returns:
an enumeration of the values in this hashtable.
See Also:
java.util.Enumeration

get

public abstract Object get(Object key)
Returns the value to which the specified key is mapped in this hashtable.
Parameters:
key - - a key in the hashtable.
Returns:
the value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.

mapType

public static int mapType(String type)
Map the type in String into an int to represent the lru cache type.

put

public abstract Object put(Object key,
                           Object value)
Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key, before it is diposed by the least-recently-used map.

Parameters:
key - the hashtable key.
value - the value.
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one.

remove

public abstract Object remove(Object key)
Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.
Parameters:
key - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.

Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com