| java.lang.Object org.ofbiz.base.util.cache.UtilCache
UtilCache | public class UtilCache implements Serializable(Code) | | Generalized caching utility. Provides a number of caching features:
- Limited or unlimited element capacity
- If limited, removes elements with the LRU (Least Recently Used) algorithm
- Keeps track of when each element was loaded into the cache
- Using the expireTime can report whether a given element has expired
- Counts misses and hits
|
Constructor Summary | |
public | UtilCache(String cacheName, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore) Constructor which specifies the cacheName as well as the maxSize, expireTime and useSoftReference. | public | UtilCache(String cacheName, int maxSize, long expireTime, boolean useSoftReference) | public | UtilCache(String cacheName, int maxSize, long expireTime) Constructor which specifies the cacheName as well as the maxSize and expireTime. | public | UtilCache(int maxSize, long expireTime) Constructor which specifies the maxSize and expireTime. | public | UtilCache(String cacheName, boolean useSoftReference) This constructor takes a name for the cache, puts itself in the utilCacheTable. | public | UtilCache(String cacheName) This constructor takes a name for the cache, puts itself in the utilCacheTable. | public | UtilCache() 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. |
Method Summary | |
public void | addListener(CacheListener listener) | public synchronized void | clear() | public static void | clearAllCaches() | public static void | clearCache(String cacheName) | public static void | clearCachesThatStartWith(String startsWith) | public void | clearCounters() | public void | clearExpired() | public static void | clearExpiredFromAllCaches() | public boolean | containsKey(Object key) Returns a boolean specifying whether or not an element with the specified key is in the cache. | public Object | get(Object key) Gets an element from the cache according to the specified key. | public Set | getCacheLineKeys() NOTE: this returns an unmodifiable copy of the keySet, so removing from here won't have an effect,
and calling a remove while iterating through the set will not cause a concurrent modification exception.
This behavior is necessary for now for the persisted cache feature. | public Collection | getCacheLineValues() | public long | getExpireTime() | public long | getHitCount() | protected CacheLine | getInternal(Object key, boolean countGet) | protected CacheLine | getInternalNoCheck(Object key) | public long | getMaxSize() | public long | getMissCountExpired() | public long | getMissCountNotFound() | public long | getMissCountSoftRef() | public long | getMissCountTotal() | public String | getName() Getter for the name of the UtilCache instance. | protected String | getNextDefaultIndex(String cacheName) | public static String | getPropertyParam(ResourceBundle res, String[] propNames, String parameter) | public long | getRemoveHitCount() | public long | getRemoveMissCount() | public long | getSizeInBytes() | public boolean | getUseFileSystemStore() | public boolean | getUseSoftReference() | 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. | protected boolean | hasExpired(CacheLine line) | protected void | noteAddition(Object key, Object newValue) | protected void | noteRemoval(Object key, Object oldValue) | protected void | noteUpdate(Object key, Object newValue, Object oldValue) | public synchronized Object | put(Object key, Object value) | public synchronized Object | put(Object key, Object value, long expireTime) | public synchronized Object | remove(Object key) | protected synchronized Object | removeInternal(Object key, boolean countRemove) | public void | removeListener(CacheListener listener) | public void | setExpireTime(long expireTime) Sets the expire time for the cache elements. | public void | setMaxSize(int maxSize) Sets the maximum number of elements in the cache. | protected void | setPropertiesParams(String cacheName) | public void | setPropertiesParams(String[] propNames) | public void | setUseSoftReference(boolean useSoftReference) | public long | size() | public static boolean | validKey(String cacheName, Object key) | public List | values() |
cacheLineTable | public CacheLineTable cacheLineTable(Code) | | A hashtable containing a CacheLine object with a value and a loadTime for each element.
|
defaultIndices | protected static Map defaultIndices(Code) | | An index number appended to utilCacheTable names when there are conflicts.
|
expireTime | protected long expireTime(Code) | | Specifies the amount of time since initial loading before an element will be reported as expired.
If set to 0, elements will never expire.
|
hitCount | protected long hitCount(Code) | | A count of the number of cache hits
|
listeners | protected Set listeners(Code) | | The set of listeners to receive notifcations when items are modidfied(either delibrately or because they were expired).
|
maxInMemory | protected int maxInMemory(Code) | | |
maxSize | protected int maxSize(Code) | | 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.
|
missCountExpired | protected long missCountExpired(Code) | | A count of the number of cache misses because it expired
|
missCountNotFound | protected long missCountNotFound(Code) | | A count of the number of cache misses because it is not found in the cache
|
missCountSoftRef | protected long missCountSoftRef(Code) | | A count of the number of cache misses because it was cleared from the Soft Reference (ie garbage collection, etc)
|
name | protected String name(Code) | | The name of the UtilCache instance, is also the key for the instance in utilCacheTable.
|
removeHitCount | protected long removeHitCount(Code) | | A count of the number of cache hits on removes
|
removeMissCount | protected long removeMissCount(Code) | | A count of the number of cache misses on removes
|
useFileSystemStore | protected boolean useFileSystemStore(Code) | | Specifies whether or not to use file base stored for this cache, defautls to false
|
useSoftReference | protected boolean useSoftReference(Code) | | Specifies whether or not to use soft references for this cache, defaults to false
|
utilCacheTable | public static Map utilCacheTable(Code) | | A static Map to keep track of all of the UtilCache instances.
|
UtilCache | public UtilCache(String cacheName, int maxSize, int maxInMemory, long expireTime, boolean useSoftReference, boolean useFileSystemStore)(Code) | | Constructor which specifies the cacheName as well as the maxSize, expireTime and useSoftReference.
The passed maxSize, expireTime and useSoftReference will be overridden by values from cache.properties if found.
Parameters: maxSize - The maxSize member is set to this value Parameters: expireTime - The expireTime member is set to this value Parameters: cacheName - The name of the cache. Parameters: useSoftReference - Specifies whether or not to use soft references for this cache. |
UtilCache | public UtilCache(String cacheName, int maxSize, long expireTime, boolean useSoftReference)(Code) | | |
UtilCache | public UtilCache(String cacheName, int maxSize, long expireTime)(Code) | | Constructor which specifies the cacheName as well as the maxSize and expireTime.
The passed maxSize and expireTime will be overridden by values from cache.properties if found.
Parameters: maxSize - The maxSize member is set to this value Parameters: expireTime - The expireTime member is set to this value Parameters: cacheName - The name of the cache. |
UtilCache | public UtilCache(int maxSize, long expireTime)(Code) | | Constructor which specifies the maxSize and expireTime.
Parameters: maxSize - The maxSize member is set to this value Parameters: expireTime - The expireTime member is set to this value |
UtilCache | public UtilCache(String cacheName, boolean useSoftReference)(Code) | | This constructor takes a name for the cache, puts itself in the utilCacheTable.
It also uses the cacheName to lookup the initialization parameters from cache.properties.
Parameters: cacheName - The name of the cache. |
UtilCache | public UtilCache(String cacheName)(Code) | | This constructor takes a name for the cache, puts itself in the utilCacheTable.
It also uses the cacheName to lookup the initialization parameters from cache.properties.
Parameters: cacheName - The name of the cache. |
UtilCache | public UtilCache()(Code) | | 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.
|
addListener | public void addListener(CacheListener listener)(Code) | | Adds an event listener for key removals
|
clear | public synchronized void clear()(Code) | | Removes all elements from this cache
|
clearAllCaches | public static void clearAllCaches()(Code) | | Removes all elements from this cache
|
clearCache | public static void clearCache(String cacheName)(Code) | | |
clearCachesThatStartWith | public static void clearCachesThatStartWith(String startsWith)(Code) | | |
clearCounters | public void clearCounters()(Code) | | Clears the hit and miss counters
|
clearExpired | public void clearExpired()(Code) | | Clears all expired cache entries; also clear any cache entries where the SoftReference in the CacheLine object has been cleared by the gc
|
clearExpiredFromAllCaches | public static void clearExpiredFromAllCaches()(Code) | | Clears all expired cache entries from all caches
|
containsKey | public boolean containsKey(Object key)(Code) | | 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.
Parameters: 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 |
get | public Object get(Object key)(Code) | | 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.
Parameters: 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 |
getCacheLineKeys | public Set getCacheLineKeys()(Code) | | NOTE: this returns an unmodifiable copy of the keySet, so removing from here won't have an effect,
and calling a remove while iterating through the set will not cause a concurrent modification exception.
This behavior is necessary for now for the persisted cache feature.
|
getExpireTime | public long getExpireTime()(Code) | | return the current expire time for the cache elements
The expire time for the cache elements |
getHitCount | public long getHitCount()(Code) | | Returns the number of successful hits on the cache
The number of successful cache hits |
getMaxSize | public long getMaxSize()(Code) | | Returns the current maximum number of elements in the cache
The maximum number of elements in the cache |
getMissCountExpired | public long getMissCountExpired()(Code) | | Returns the number of cache misses from entries that are expired
The number of cache misses |
getMissCountNotFound | public long getMissCountNotFound()(Code) | | Returns the number of cache misses from entries that are not found in the cache
The number of cache misses |
getMissCountSoftRef | public long getMissCountSoftRef()(Code) | | Returns the number of cache misses from entries that are have had the soft reference cleared out (by garbage collector and such)
The number of cache misses |
getMissCountTotal | public long getMissCountTotal()(Code) | | Returns the number of cache misses caused by any reason
The number of cache misses |
getName | public String getName()(Code) | | Getter for the name of the UtilCache instance.
The name of the instance |
getRemoveHitCount | public long getRemoveHitCount()(Code) | | |
getRemoveMissCount | public long getRemoveMissCount()(Code) | | |
getSizeInBytes | public long getSizeInBytes()(Code) | | |
getUseFileSystemStore | public boolean getUseFileSystemStore()(Code) | | |
getUseSoftReference | public boolean getUseSoftReference()(Code) | | Return whether or not the cache lines should use a soft reference to the data
|
hasExpired | public boolean hasExpired(Object key)(Code) | | 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.
Parameters: 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 |
noteAddition | protected void noteAddition(Object key, Object newValue)(Code) | | Send a key addition event to all registered listeners
|
noteRemoval | protected void noteRemoval(Object key, Object oldValue)(Code) | | Send a key removal event to all registered listeners
|
noteUpdate | protected void noteUpdate(Object key, Object newValue, Object oldValue)(Code) | | Send a key update event to all registered listeners
|
put | public synchronized Object put(Object key, Object value)(Code) | | Puts or loads the passed element into the cache
Parameters: key - The key for the element, used to reference it in the hastables and LRU linked list Parameters: value - The value of the element |
put | public synchronized Object put(Object key, Object value, long expireTime)(Code) | | Puts or loads the passed element into the cache
Parameters: key - The key for the element, used to reference it in the hastables and LRU linked list Parameters: value - The value of the element Parameters: expireTime - how long to keep this key in the cache |
remove | public synchronized Object remove(Object key)(Code) | | Removes an element from the cache according to the specified key
Parameters: key - The key for the element, used to reference it in the hastables and LRU linked list The value of the removed element specified by the key |
removeInternal | protected synchronized Object removeInternal(Object key, boolean countRemove)(Code) | | This is used for internal remove calls because we only want to count external calls
|
removeListener | public void removeListener(CacheListener listener)(Code) | | Removes an event listener for key removals
|
setExpireTime | public void setExpireTime(long expireTime)(Code) | | Sets the expire time for the cache elements.
If 0, elements never expire.
Parameters: expireTime - The expire time for the cache elements |
setMaxSize | public void setMaxSize(int maxSize)(Code) | | Sets the maximum number of elements in the cache.
If 0, there is no maximum.
Parameters: maxSize - The maximum number of elements in the cache |
setPropertiesParams | protected void setPropertiesParams(String cacheName)(Code) | | |
setPropertiesParams | public void setPropertiesParams(String[] propNames)(Code) | | |
setUseSoftReference | public void setUseSoftReference(boolean useSoftReference)(Code) | | Set whether or not the cache lines should use a soft reference to the data
|
size | public long size()(Code) | | Returns the number of elements currently in the cache
The number of elements currently in the cache |
validKey | public static boolean validKey(String cacheName, Object key)(Code) | | Checks for a non-expired key in a specific cache
|
|
|