com.jdon.cache
类 UtilCache

java.lang.Object
  继承者 com.jdon.cache.UtilCache

public class UtilCache
extends Object

Generalized caching utility. Provides a number of caching features:


字段摘要
 Map cacheLineTable
          A hashtable containing a CacheLine object with a value and a loadTime for each element. for above jdk1.5
protected  long expireTime
          Specifies the amount of time since initial loading before an element will be reported as expired.
protected  long hitCount
          A count of the number of cache hits
 ConcurrentLinkedList keyLRUList
          A list of the elements order by Least Recent Use
protected  long maxSize
          The maximum number of elements in the cache.
protected  long missCount
          A count of the number of cache misses
static String module
           
protected  boolean useSoftReference
          Specifies whether or not to use soft references for this cache, defaults to false
 
构造方法摘要
UtilCache(int maxSize, long expireTime, boolean useSoftReference)
           
UtilCache(PropsUtil propsUtil)
          Default constructor, all members stay at default values as defined in cache.properties, or the defaults in this file if cache.properties is not found, or there are no 'default' entries in it.
 
方法摘要
 void clear()
          Removes all elements from this cache
 void clearAllCaches()
          Removes all elements from this cache
 void clearCounters()
          Clears the hit and miss counters
 void clearExpired()
          Clears all expired cache entries; also clear any cache entries where the SoftReference in the CacheLine object has been cleared by the gc
 boolean containsKey(Object key)
          Returns a boolean specifying whether or not an element with the specified key is in the cache.
 Object get(Object key)
          Gets an element from the cache according to the specified key.
 long getExpireTime()
          return the current expire time for the cache elements
 long getHitCount()
          Returns the number of successful hits on the cache
 long getMaxSize()
          Returns the current maximum number of elements in the cache
 long getMissCount()
          Returns the number of cache misses
 boolean getUseSoftReference()
          Return whether or not the cache lines should use a soft reference to the data
protected  boolean hasExpired(CacheLine line)
           
 boolean hasExpired(Object key)
          Returns a boolean specifying whether or not the element corresponding to the key has expired.
 Set keySet()
           
 void put(Object key, Object value)
          Puts or loads the passed element into the cache
 void remove(Object key)
          Removes an element from the cache according to the specified key
 void setExpireTime(long expireTime)
          Sets the expire time for the cache elements.
 void setMaxSize(long maxSize)
          Sets the maximum number of elements in the cache.
protected  void setPropertiesParams(PropsUtil propsUtil, String cacheName)
           
 long size()
          Returns the number of elements currently in the cache
 void startMon(long expireTime)
           
 void stop()
           
 Collection values()
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

module

public static String module

keyLRUList

public final ConcurrentLinkedList keyLRUList
A list of the elements order by Least Recent Use


cacheLineTable

public final Map cacheLineTable
A hashtable containing a CacheLine object with a value and a loadTime for each element. for above jdk1.5


hitCount

protected volatile long hitCount
A count of the number of cache hits


missCount

protected volatile long missCount
A count of the number of cache misses


maxSize

protected volatile long maxSize
The maximum number of elements in the cache. If set to 0, there will be no limit on the number of elements in the cache.


expireTime

protected volatile long expireTime
Specifies the amount of time since initial loading before an element will be reported as expired. If set to 0, elements will never expire.


useSoftReference

protected volatile boolean useSoftReference
Specifies whether or not to use soft references for this cache, defaults to false

构造方法详细信息

UtilCache

public UtilCache(PropsUtil propsUtil)
Default constructor, all members stay at default values as defined in cache.properties, or the defaults in this file if cache.properties is not found, or there are no 'default' entries in it.


UtilCache

public UtilCache(int maxSize,
                 long expireTime,
                 boolean useSoftReference)
方法详细信息

startMon

public void startMon(long expireTime)

setPropertiesParams

protected void setPropertiesParams(PropsUtil propsUtil,
                                   String cacheName)

put

public void put(Object key,
                Object value)
Puts or loads the passed element into the cache

参数:
key - The key for the element, used to reference it in the hastables and LRU linked list
value - The value of the element

get

public Object get(Object key)
Gets an element from the cache according to the specified key. If the requested element hasExpired, it is removed before it is looked up which causes the function to return null.

参数:
key - The key for the element, used to reference it in the hastables and LRU linked list
返回:
The value of the element specified by the key

remove

public void remove(Object key)
Removes an element from the cache according to the specified key

参数:
key - The key for the element, used to reference it in the hastables and LRU linked list

keySet

public Set keySet()

values

public Collection values()

clear

public void clear()
Removes all elements from this cache


clearAllCaches

public void clearAllCaches()
Removes all elements from this cache


getHitCount

public long getHitCount()
Returns the number of successful hits on the cache

返回:
The number of successful cache hits

getMissCount

public long getMissCount()
Returns the number of cache misses

返回:
The number of cache misses

clearCounters

public void clearCounters()
Clears the hit and miss counters


setMaxSize

public void setMaxSize(long maxSize)
Sets the maximum number of elements in the cache. If 0, there is no maximum.

参数:
maxSize - The maximum number of elements in the cache

getMaxSize

public long getMaxSize()
Returns the current maximum number of elements in the cache

返回:
The maximum number of elements in the cache

setExpireTime

public void setExpireTime(long expireTime)
Sets the expire time for the cache elements. If 0, elements never expire.

参数:
expireTime - The expire time for the cache elements

getExpireTime

public long getExpireTime()
return the current expire time for the cache elements

返回:
The expire time for the cache elements

getUseSoftReference

public boolean getUseSoftReference()
Return whether or not the cache lines should use a soft reference to the data


size

public long size()
Returns the number of elements currently in the cache

返回:
The number of elements currently in the cache

containsKey

public boolean containsKey(Object key)
Returns a boolean specifying whether or not an element with the specified key is in the cache. If the requested element hasExpired, it is removed before it is looked up which causes the function to return false.

参数:
key - The key for the element, used to reference it in the hastables and LRU linked list
返回:
True is the cache contains an element corresponding to the specified key, otherwise false

hasExpired

public boolean hasExpired(Object key)
Returns a boolean specifying whether or not the element corresponding to the key has expired. Only returns true if element is in cache and has expired. Error conditions return false, if no expireTable entry, returns true. Always returns false if expireTime <= 0. Also, if SoftReference in the CacheLine object has been cleared by the gc return true.

参数:
key - The key for the element, used to reference it in the hastables and LRU linked list
返回:
True is the element corresponding to the specified key has expired, otherwise false

hasExpired

protected boolean hasExpired(CacheLine line)

clearExpired

public void clearExpired()
Clears all expired cache entries; also clear any cache entries where the SoftReference in the CacheLine object has been cleared by the gc


stop

public void stop()


Copyright © 2013. All Rights Reserved.