Package org.apache.fulcrum.cache.impl
Class JCSCacheService
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.fulcrum.cache.impl.JCSCacheService
- 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 JCSCacheService
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 JCSCacheService
- Version:
- $Id$
- Author:
- Thomas Vandahl
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
Cache 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> void
addObject
(String objectId, CachedObject<T> cachedObject) Adds an object to the cache.void
configure
(org.apache.avalon.framework.configuration.Configuration config) void
dispose()
void
Flush the cache of all objects.List
<CachedObject<?>> Returns a copy of the non-expired CachedObjects in the cache as a list.int
Returns the current size of the cache.getKeys()
Returns a copy of keys to objects in the cache as a list.int
Returns the number of objects in the cache.<T> CachedObject
<T> Gets a cached object given its id (a String).void
void
removeObject
(String objectId) Removes an object from the cache.void
run()
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
-
JCSCacheService
public JCSCacheService()
-
-
Method Details
-
configure
public void configure(org.apache.avalon.framework.configuration.Configuration config) throws org.apache.avalon.framework.configuration.ConfigurationException - Specified by:
configure
in interfaceorg.apache.avalon.framework.configuration.Configurable
- Throws:
org.apache.avalon.framework.configuration.ConfigurationException
- See Also:
-
initialize
- Specified by:
initialize
in interfaceorg.apache.avalon.framework.activity.Initializable
- Throws:
Exception
- See Also:
-
dispose
public void dispose()- Specified by:
dispose
in interfaceorg.apache.avalon.framework.activity.Disposable
- See Also:
-
getObject
Description copied from interface:GlobalCacheService
Gets a cached object given its id (a String).- Specified by:
getObject
in 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:
-
addObject
Description copied from interface:GlobalCacheService
Adds an object to the cache.- Specified by:
addObject
in interfaceGlobalCacheService
- Type Parameters:
T
- type of object to add- Parameters:
objectId
- The String id for the object.cachedObject
- The object to add to the cache.- See Also:
-
removeObject
Description copied from interface:GlobalCacheService
Removes an object from the cache.- Specified by:
removeObject
in interfaceGlobalCacheService
- Parameters:
objectId
- The String id for the object.- See Also:
-
getKeys
Description copied from interface:GlobalCacheService
Returns a copy of keys to objects in the cache as a list. Note that keys to expired objects are not returned.- Specified by:
getKeys
in interfaceGlobalCacheService
- Returns:
- A List of
String
's representing the keys to objects in the cache. - See Also:
-
getCachedObjects
Description copied from interface:GlobalCacheService
Returns a copy of the non-expired CachedObjects in the cache as a list.- Specified by:
getCachedObjects
in interfaceGlobalCacheService
- Returns:
- A List of
CachedObject
objects held in the cache - See Also:
-
run
public void run()Circle through the cache and refresh stale objects. Frequency is determined by the cacheCheckFrequency property. -
getCacheSize
Description copied from interface:GlobalCacheService
Returns the current size of the cache.- Specified by:
getCacheSize
in interfaceGlobalCacheService
- Returns:
- int representing current cache size in number of bytes
- Throws:
IOException
- if unable to return cache size- See Also:
-
getNumberOfObjects
public int getNumberOfObjects()Description copied from interface:GlobalCacheService
Returns the number of objects in the cache.- Specified by:
getNumberOfObjects
in interfaceGlobalCacheService
- Returns:
- int The current number of objects in the cache.
- See Also:
-
flushCache
public void flushCache()Description copied from interface:GlobalCacheService
Flush the cache of all objects.- Specified by:
flushCache
in interfaceGlobalCacheService
- See Also:
-