|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.ashkay.ObjectCache
ObjectCache is the default implementation of an object caching mechanism.
ObjectCaching makes use of a Factory for the creation of objects that are not
cached. The user of an ObjectCache provides an implementation of
ObjectFactory to the cache. If the cache does not find the object asked for,
it uses the factory to create the object, cache it, and return it.
Looking up an object from cache requires a key. The key is a unique
identifier. The key could be a database record id, a URI, or any other id
that is guaranteed to be unique. The key is also used by the factory to
create the object. The factory ought to be able to construct an object given
only a key. This key is then used as the key in the cache.
Gets may also be done with a data parameter. The data provides construction
information to the factory about the object being created. The cache does not
use the data directly but, if the object is not cached, will pass the data
to the factory. Common use of the data would be if the user of the cache
has an "un-objectified" data source (e.g. XML document) from some other
source that would save the factory the lookup call. So, if the user has the
key and the data and wants the object form of the data, it simply asks the
cache passing in the key and data.
The ObjectCache uses CachingStrategies to detirmine a strategy for caching
objects that is stores. These strategies may affect caching in any number of
ways. You might want to use a cache that does not prevent garbage collection
of cached objects, only getting benefit of the cache as memory allows. A
client may want to place timeouts for objects to force them to be re-loaded
after a period of time. Any number of caching strategies may be used, but be
careful not to use two caching strategies that work in opposition. That is
a check left to the user at this point.
Constructor Summary | |
ObjectCache()
|
|
ObjectCache(java.util.List theStrategies)
Constructs an ObjectCache without a factory using the strategies indicated. |
|
ObjectCache(ObjectFactory aFactory)
Constructs an ObjectCache from a factory using the default strategy of NONE. |
|
ObjectCache(ObjectFactory aFactory,
java.util.List theStrategies)
Constructs an ObjectCache from a factory and strategy. |
Method Summary | |
ObjectCache |
addStrategy(CachingStrategy aStrategy)
Adds a caching strategy to this cache |
void |
clear()
Clears the cache |
java.lang.Object |
evict(java.lang.Object key)
Forcefully evicts an object/key from the cache. |
java.lang.Object |
get(java.lang.Object key)
Finds an object in the cache and returns it. |
java.lang.Object |
get(java.lang.Object key,
java.lang.Object data)
Finds an object in the cache and returns it. |
void |
put(java.lang.Object key,
java.lang.Object value)
|
ObjectCache |
removeStrategy(CachingStrategy aStrategy)
Removes a strategy from this cache |
int |
size()
Returns the size of the cache |
boolean |
usesStrategy(CachingStrategy aStrategy)
Checks if this cache uses the specified caching strategy |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ObjectCache()
public ObjectCache(ObjectFactory aFactory)
aFactory
- - the factory for the cache to usepublic ObjectCache(java.util.List theStrategies)
theStrategies
- public ObjectCache(ObjectFactory aFactory, java.util.List theStrategies)
aFactory
- - the factory for the cache to usetheStrategies
- - the caching strategies for this cacheMethod Detail |
public ObjectCache addStrategy(CachingStrategy aStrategy)
aStrategy
- - the strategy to addpublic ObjectCache removeStrategy(CachingStrategy aStrategy)
aStrategy
- - the strategy to removepublic boolean usesStrategy(CachingStrategy aStrategy)
aStrategy
- - the strategy to checkpublic java.lang.Object get(java.lang.Object key) throws CreationException
key
- - the key to lookup
CreationException
- on any error during creationget(java.lang.Object, java.lang.Object)
public java.lang.Object evict(java.lang.Object key)
key
- to the object to evict
public java.lang.Object get(java.lang.Object key, java.lang.Object data) throws CreationException
key
- - the key to lookupdata
- - the data to aid construction
CreationException
- on any error during creationpublic void put(java.lang.Object key, java.lang.Object value)
public void clear()
public int size()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |