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
Fields Modifier and Type Field Description static long
DEFAULT_CACHE_CHECK_FREQUENCY
Cache check frequency in Millis (1000 Millis = 1 second).-
Fields inherited from interface org.apache.fulcrum.cache.GlobalCacheService
ROLE
-
-
Constructor Summary
Constructors Constructor Description JCSCacheService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <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
flushCache()
Flush the cache of all objects.List<CachedObject<?>>
getCachedObjects()
Returns a copy of the non-expired CachedObjects in the cache as a list.int
getCacheSize()
Returns the current size of the cache.List<String>
getKeys()
Returns a copy of keys to objects in the cache as a list.int
getNumberOfObjects()
Returns the number of objects in the cache.<T> CachedObject<T>
getObject(String objectId)
Gets a cached object given its id (a String).void
initialize()
void
removeObject(String objectId)
Removes an object from the cache.void
run()
Circle through the cache and refresh stale objects.
-
-
-
Field Detail
-
DEFAULT_CACHE_CHECK_FREQUENCY
public static final long DEFAULT_CACHE_CHECK_FREQUENCY
Cache check frequency in Millis (1000 Millis = 1 second). Value must be > 0. Default = 5 seconds- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JCSCacheService
public JCSCacheService()
-
-
Method Detail
-
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:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceorg.apache.avalon.framework.activity.Initializable
- Throws:
Exception
- See Also:
Initializable.initialize()
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceorg.apache.avalon.framework.activity.Disposable
- See Also:
Disposable.dispose()
-
getObject
public <T> CachedObject<T> getObject(String objectId) throws ObjectExpiredException
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:
GlobalCacheService.getObject(java.lang.String)
-
addObject
public <T> void addObject(String objectId, CachedObject<T> cachedObject)
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:
GlobalCacheService.addObject(java.lang.String, org.apache.fulcrum.cache.CachedObject)
-
removeObject
public void removeObject(String objectId)
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:
GlobalCacheService.removeObject(java.lang.String)
-
getKeys
public List<String> 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:
GlobalCacheService.getKeys()
-
getCachedObjects
public List<CachedObject<?>> 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:
GlobalCacheService.getCachedObjects()
-
run
public void run()
Circle through the cache and refresh stale objects. Frequency is determined by the cacheCheckFrequency property.
-
getCacheSize
public int getCacheSize() throws IOException
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:
GlobalCacheService.getCacheSize()
-
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:
GlobalCacheService.getNumberOfObjects()
-
flushCache
public void flushCache()
Description copied from interface:GlobalCacheService
Flush the cache of all objects.- Specified by:
flushCache
in interfaceGlobalCacheService
- See Also:
GlobalCacheService.flushCache()
-
-