Package org.apache.fulcrum.cache.impl
Class DefaultGlobalCacheService
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.fulcrum.cache.impl.DefaultGlobalCacheService
- All Implemented Interfaces:
- Runnable,- org.apache.avalon.framework.activity.Disposable,- org.apache.avalon.framework.activity.Initializable,- org.apache.avalon.framework.configuration.Configurable,- org.apache.avalon.framework.logger.LogEnabled,- org.apache.avalon.framework.thread.ThreadSafe,- GlobalCacheService
public class DefaultGlobalCacheService
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements GlobalCacheService, Runnable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.thread.ThreadSafe
This Service functions as a Global Cache. A global cache is a good place to
 store items that you may need to access often but don't necessarily need (or
 want) to fetch from the database everytime. A good example would be a look up
 table of States that you store in a database and use throughout your
 application. Since information about States doesn't change very often, you
 could store this information in the Global Cache and decrease the overhead of
 hitting the database everytime you need State information.
- Version:
- $Id$
- Author:
- Dave Bryson, Jon S. Stevens, John Thorhauer, Henning P. Schmiedehausen, Eric Pugh, Peter CourefreshableCachedObjectux
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ConcurrentHashMap<String, CachedObject<?>> The cache.static final StringThe property for the Cache check frequencystatic final longCache check frequency in Millis (1000 Millis = 1 second).static final intInitial size of hash table Value must be > 0.static final StringThe property for the InitalCacheSizeFields inherited from interface org.apache.fulcrum.cache.GlobalCacheServiceROLE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescription<T> voidaddObject(String objectId, CachedObject<T> object) Adds an object to the cache.voidIterate through the cache and remove or refresh stale objects.voidconfigure(org.apache.avalon.framework.configuration.Configuration conf) Avalon component lifecycle methodvoiddispose()Avalon component lifecycle methodvoidFlush the cache of all objects.longGet the Cache Check Frequency in millisecondsList<CachedObject<?>> Returns a copy of the non-expired CachedObjects in the cache as a list.intReturns the current size of the cache.getKeys()Returns a copy of keys to objects in the cache as a list.intReturns the number of objects currently stored in the cache<T> CachedObject<T> Returns an item from the cache. /** Returns an item from the cache.voidAvalon component lifecycle methodvoidremoveObject(String objectId) Removes an object from the cache.voidrun()Circle through the cache and remove stale objects.Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabledenableLogging, getLogger, setupLogger, setupLogger, setupLogger
- 
Field Details- 
DEFAULT_INITIAL_CACHE_SIZEpublic static final int DEFAULT_INITIAL_CACHE_SIZEInitial size of hash table Value must be > 0. Default = 20- See Also:
 
- 
INITIAL_CACHE_SIZEThe property for the InitalCacheSize- See Also:
 
- 
CACHE_CHECK_FREQUENCYThe property for the Cache check frequency- See Also:
 
- 
DEFAULT_CACHE_CHECK_FREQUENCYpublic static final long DEFAULT_CACHE_CHECK_FREQUENCYCache check frequency in Millis (1000 Millis = 1 second). Value must be > 0. Default = 5 seconds- See Also:
 
- 
cacheThe cache.
 
- 
- 
Constructor Details- 
DefaultGlobalCacheServicepublic DefaultGlobalCacheService()
 
- 
- 
Method Details- 
getCacheCheckFrequencypublic long getCacheCheckFrequency()Get the Cache Check Frequency in milliseconds- Returns:
- the time between two cache check runs in milliseconds
 
- 
getObjectReturns an item from the cache. /** Returns an item from the cache. RefreshableCachedObject will be refreshed if it is expired and not untouched.- Specified by:
- getObjectin interface- GlobalCacheService
- Type Parameters:
- T- type of object to return
- Parameters:
- objectId- The key of the stored object.
- Returns:
- The object from the cache.
- Throws:
- ObjectExpiredException- when either the object is not in the cache or it has expired.
 
- 
addObjectAdds an object to the cache.- Specified by:
- addObjectin interface- GlobalCacheService
- Type Parameters:
- T- type of object to add
- Parameters:
- objectId- The key to store the object by.
- object- The object to cache.
 
- 
removeObjectRemoves an object from the cache.- Specified by:
- removeObjectin interface- GlobalCacheService
- Parameters:
- objectId- The String id for the object.
 
- 
getKeysReturns a copy of keys to objects in the cache as a list. Note that keys to expired objects are not returned.- Specified by:
- getKeysin interface- GlobalCacheService
- Returns:
- A List of String's representing the keys to objects in the cache.
 
- 
getCachedObjectsReturns a copy of the non-expired CachedObjects in the cache as a list.- Specified by:
- getCachedObjectsin interface- GlobalCacheService
- Returns:
- A List of CachedObjectobjects held in the cache
 
- 
runpublic void run()Circle through the cache and remove stale objects. Frequency is determined by the cacheCheckFrequency property.
- 
clearCachepublic void clearCache()Iterate through the cache and remove or refresh stale objects.
- 
getNumberOfObjectspublic int getNumberOfObjects()Returns the number of objects currently stored in the cache- Specified by:
- getNumberOfObjectsin interface- GlobalCacheService
- Returns:
- int number of object in the cache
 
- 
getCacheSizeReturns the current size of the cache.- Specified by:
- getCacheSizein interface- GlobalCacheService
- Returns:
- int representing current cache size in number of bytes
- Throws:
- IOException- if unable to return cache size
 
- 
flushCachepublic void flushCache()Flush the cache of all objects.- Specified by:
- flushCachein interface- GlobalCacheService
 
- 
configurepublic void configure(org.apache.avalon.framework.configuration.Configuration conf) throws org.apache.avalon.framework.configuration.ConfigurationException Avalon component lifecycle method- Specified by:
- configurein interface- org.apache.avalon.framework.configuration.Configurable
- Throws:
- org.apache.avalon.framework.configuration.ConfigurationException
 
- 
initializeAvalon component lifecycle method- Specified by:
- initializein interface- org.apache.avalon.framework.activity.Initializable
- Throws:
- Exception
 
- 
disposepublic void dispose()Avalon component lifecycle method- Specified by:
- disposein interface- org.apache.avalon.framework.activity.Disposable
 
 
-