|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ls.util.cache.CacheTimer
This class is used for caching data that will be used in different class.
There is an internal static map defined to store all cache types. User can define his/her own type in the constructor. If this type "cacheId" is already defined in the cache list then this will be used, else a new cache for the required "cacheId" will be created. All cache types are synchronized. User can access any data which is inserted by another one.
All information are stored with a time stamp. When user wants to retrieve these data,
the age of the data is checked. If it is an old data than system returns null. If
user does not want to use this property then has to set the maxDuration variable to
NONTERMINATING_LIFETIME
in the constructor or use setMaxDuration(long)
method.
Field Summary | |
static long |
DEFAULT_MAX_LIFETIME
The default maximum lifetime for an object in the hash (60 seconds) |
static long |
NONTERMINATING_LIFETIME
If users sets the maxDuration to this value then the the age of the variable will not be checked while retrieving data |
Constructor Summary | |
CacheTimer(String cacheId)
Constructor, that creates the hash table for a specific "cacheId". |
|
CacheTimer(String cacheId,
long newMaxDuration)
Constructor, that creates the hash table and sets the life time of a variable. |
Method Summary | |
void |
clear()
Clears all data in the hash |
void |
clearOldData()
Clears all data which are old (duration > maxDuration) |
Object |
get(Object key)
Retrieves a data from the internal hash |
StringBuffer |
getCacheStatus()
Returns the cache status and some statistics |
void |
put(Object key,
Object value)
Inserts a data to the hash. |
Object |
remove(Object key)
Removes a data from the internal hash |
void |
setMaxDuration(long newMaxDuration)
Sets the maximum duration time to a new value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final long DEFAULT_MAX_LIFETIME
public static final long NONTERMINATING_LIFETIME
Constructor Detail |
public CacheTimer(String cacheId)
DEFAULT_MAX_LIFETIME
.cacheId
- The ID of the cache.public CacheTimer(String cacheId, long newMaxDuration)
NONTERMINATING_LIFETIME
then the
maxduration values will be set to NONTERMINATING_LIFETIME
.In this case
the age of the variable will not be checked while retrieving datacacheId
- The ID of the cache.newMaxDuration
- The maximum duration time for the variables in the cacheMethod Detail |
public void setMaxDuration(long newMaxDuration)
DEFAULT_MAX_LIFETIME
. The unit of the newMaxDuration parameter is miliseconds.
If user specifies a negativ value then the maxduration values will be set to
NONTERMINATING_LIFETIME
. In this case the age of the variable will not be checked while
retrieving data.newMaxDuration
- The maximum duration time for the variables in the cachepublic Object remove(Object key)
key
- The key of the data that will be deletedpublic Object get(Object key)
key
- The key of the data that will be retrievedpublic void clear()
public void clearOldData()
public void put(Object key, Object value)
key
- The key of the datavalue
- The vaue of the datapublic StringBuffer getCacheStatus()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |