Package org.apache.fulcrum.cache.impl
Class EHCacheService
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.fulcrum.cache.impl.EHCacheService
- 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 EHCacheService
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements GlobalCacheService, Runnable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.thread.ThreadSafe
Default implementation of EHCacheService (Ehcache 2)
- Author:
- Eric Pugh, Thomas Vandahl
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longCache check frequency in Millis (1000 Millis = 1 second).Fields inherited from interface org.apache.fulcrum.cache.GlobalCacheService
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> voidaddObject(String objectId, CachedObject<T> object) Adds an object to the cache.voidconfigure(org.apache.avalon.framework.configuration.Configuration config) voiddispose()voidFlush the cache of all objects.List<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 in the cache.<T> CachedObject<T> Gets a cached object given its id (a String).voidvoidremoveObject(String objectId) Removes an object from the cache.voidrun()Circle through the cache and refresh stale objects.Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
DEFAULT_CACHE_CHECK_FREQUENCY
public static final long DEFAULT_CACHE_CHECK_FREQUENCYCache check frequency in Millis (1000 Millis = 1 second). Value must be > 0. Default = 5 seconds- See Also:
-
-
Constructor Details
-
EHCacheService
public EHCacheService()
-
-
Method Details
-
configure
public void configure(org.apache.avalon.framework.configuration.Configuration config) throws org.apache.avalon.framework.configuration.ConfigurationException - Specified by:
configurein interfaceorg.apache.avalon.framework.configuration.Configurable- Throws:
org.apache.avalon.framework.configuration.ConfigurationException- See Also:
-
initialize
- Specified by:
initializein interfaceorg.apache.avalon.framework.activity.Initializable- Throws:
Exception- See Also:
-
dispose
public void dispose()- Specified by:
disposein interfaceorg.apache.avalon.framework.activity.Disposable- See Also:
-
addObject
Description copied from interface:GlobalCacheServiceAdds an object to the cache.- Specified by:
addObjectin interfaceGlobalCacheService- Type Parameters:
T- type of object to add- Parameters:
objectId- The String id for the object.object- The object to add to the cache.- See Also:
-
flushCache
public void flushCache()Description copied from interface:GlobalCacheServiceFlush the cache of all objects.- Specified by:
flushCachein interfaceGlobalCacheService- See Also:
-
getCachedObjects
Description copied from interface:GlobalCacheServiceReturns a copy of the non-expired CachedObjects in the cache as a list.- Specified by:
getCachedObjectsin interfaceGlobalCacheService- Returns:
- A List of
CachedObjectobjects held in the cache - See Also:
-
getCacheSize
Description copied from interface:GlobalCacheServiceReturns the current size of the cache.- Specified by:
getCacheSizein interfaceGlobalCacheService- Returns:
- int representing current cache size in number of bytes
- Throws:
IOException- if unable to return cache size- See Also:
-
getKeys
Description copied from interface:GlobalCacheServiceReturns a copy of keys to objects in the cache as a list. Note that keys to expired objects are not returned.- Specified by:
getKeysin interfaceGlobalCacheService- Returns:
- A List of
String's representing the keys to objects in the cache. - See Also:
-
getNumberOfObjects
public int getNumberOfObjects()Description copied from interface:GlobalCacheServiceReturns the number of objects in the cache.- Specified by:
getNumberOfObjectsin interfaceGlobalCacheService- Returns:
- int The current number of objects in the cache.
- See Also:
-
getObject
Description copied from interface:GlobalCacheServiceGets a cached object given its id (a String).- Specified by:
getObjectin interfaceGlobalCacheService- Type Parameters:
T- type of object to return- Parameters:
objectId- The String id for the object.- Returns:
- A CachedObject.
- Throws:
ObjectExpiredException- if the object has expired in the cache.- See Also:
-
removeObject
Description copied from interface:GlobalCacheServiceRemoves an object from the cache.- Specified by:
removeObjectin interfaceGlobalCacheService- Parameters:
objectId- The String id for the object.- See Also:
-
run
public void run()Circle through the cache and refresh stale objects. Frequency is determined by the cacheCheckFrequency property.
-