org.apache.turbine.services.cache
Class TurbineGlobalCacheService
java.lang.Object
|
+--org.apache.turbine.services.BaseInitable
|
+--org.apache.turbine.services.BaseService
|
+--org.apache.turbine.services.TurbineBaseService
|
+--org.apache.turbine.services.cache.TurbineGlobalCacheService
- All Implemented Interfaces:
- GlobalCacheService, Initable, java.lang.Runnable, Service
- public class TurbineGlobalCacheService
- extends TurbineBaseService
- implements GlobalCacheService, java.lang.Runnable
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.
The following properties are needed to configure this service:
services.GlobalCacheService.classname=org.apache.turbine.services.cache.TurbineGlobalCacheService
services.GlobalCacheService.cache.initial.size=20
services.GlobalCacheService.cache.check.frequency=5000
- classname
- the classname of this service
- cache.initial.size/dt>
- Initial size of hash table use to store cached
objects. If this property is not present, the default value is 20
- cache.check.frequency
- Cache check frequency in Millis (1000
Millis = 1 second). If this property is not present, the default value is 5000
- Version:
- $Id: TurbineGlobalCacheService.java,v 1.4 2002/04/16 22:07:08 kschrader Exp $
- Author:
- Dave Bryson, Jon S. Stevens, John Thorhauer
Method Summary |
void |
addObject(java.lang.String id,
CachedObject o)
Adds an object to the cache. |
void |
clearCache()
Iterate through the cache and remove or refresh stale objects. |
void |
flushCache()
Flush the cache of all objects. |
int |
getCacheSize()
Returns the current size of the cache. |
int |
getNumberOfObjects()
Returns the number of objects currently stored in the cache |
CachedObject |
getObject(java.lang.String id)
Returns an item from the cache. |
void |
init()
Called the first time the Service is used. |
void |
removeObject(java.lang.String id)
Removes an object from the cache. |
void |
run()
Circle through the cache and remove stale objects. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_INITIAL_CACHE_SIZE
public static final int DEFAULT_INITIAL_CACHE_SIZE
- Initial size of hash table
Value must be > 0.
Default = 20
INITIAL_CACHE_SIZE
public static final java.lang.String INITIAL_CACHE_SIZE
- The property for the InitalCacheSize
CACHE_CHECK_FREQUENCY
public static final java.lang.String CACHE_CHECK_FREQUENCY
- The property for the Cache check frequency
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
TurbineGlobalCacheService
public TurbineGlobalCacheService()
- Constructor.
init
public void init()
throws InitializationException
- Called the first time the Service is used.
- Specified by:
init
in interface Initable
- Overrides:
init
in class TurbineBaseService
- Following copied from interface:
org.apache.turbine.services.Initable
- Throws:
InitializationException,
- if initialization of this
class was not successful.
getObject
public CachedObject getObject(java.lang.String id)
throws ObjectExpiredException
- Returns an item from the cache. RefreshableCachedObject will be
refreshed if it is expired not untouched.
- Specified by:
getObject
in interface GlobalCacheService
- Parameters:
id
- 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.
addObject
public void addObject(java.lang.String id,
CachedObject o)
- Adds an object to the cache.
- Specified by:
addObject
in interface GlobalCacheService
- Parameters:
id
- The key to store the object by.o
- The object to cache.
removeObject
public void removeObject(java.lang.String id)
- Removes an object from the cache.
- Specified by:
removeObject
in interface GlobalCacheService
- Parameters:
id
- The String id for the object.
run
public void run()
- Circle through the cache and remove stale objects. Frequency
is determined by the cacheCheckFrequency property.
- Specified by:
run
in interface java.lang.Runnable
clearCache
public void clearCache()
- Iterate through the cache and remove or refresh stale objects.
getNumberOfObjects
public int getNumberOfObjects()
- Returns the number of objects currently stored in the cache
- Specified by:
getNumberOfObjects
in interface GlobalCacheService
- Returns:
- int number of object in the cache
getCacheSize
public int getCacheSize()
throws java.io.IOException
- Returns the current size of the cache.
- Specified by:
getCacheSize
in interface GlobalCacheService
- Returns:
- int representing current cache size in number of bytes
flushCache
public void flushCache()
- Flush the cache of all objects.
- Specified by:
flushCache
in interface GlobalCacheService
Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.