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() |
public static String module
public final ConcurrentLinkedList keyLRUList
public final Map cacheLineTable
protected volatile long hitCount
protected volatile long missCount
protected volatile long maxSize
protected volatile long expireTime
protected volatile boolean useSoftReference
public UtilCache(PropsUtil propsUtil)
public UtilCache(int maxSize,
long expireTime,
boolean useSoftReference)
public void startMon(long expireTime)
public void put(Object key, Object value)
key - The key for the element, used to reference it in the hastables
and LRU linked listvalue - The value of the elementpublic Object get(Object key)
key - The key for the element, used to reference it in the hastables
and LRU linked listpublic void remove(Object key)
key - The key for the element, used to reference it in the hastables
and LRU linked listpublic Set keySet()
public Collection values()
public void clear()
public void clearAllCaches()
public long getHitCount()
public long getMissCount()
public void clearCounters()
public void setMaxSize(long maxSize)
maxSize - The maximum number of elements in the cachepublic long getMaxSize()
public void setExpireTime(long expireTime)
expireTime - The expire time for the cache elementspublic long getExpireTime()
public boolean getUseSoftReference()
public long size()
public boolean containsKey(Object key)
key - The key for the element, used to reference it in the hastables
and LRU linked listpublic boolean hasExpired(Object key)
key - The key for the element, used to reference it in the hastables
and LRU linked listprotected boolean hasExpired(CacheLine line)
public void clearExpired()
public void stop()
Copyright © 2018. All rights reserved.