|
JAC project AOPSYS CEDRIC & LIP6 labs |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.objectweb.jac.core.Wrapper | +--org.objectweb.jac.wrappers.CacheWrapper
CacheWrapper
implements a wrapper that caches the wrappee
methods results so that it can avoid the wrappee computations. It
can improve performances of complex computations.
Please make sure to use the rigth wrapping method.
For example, if you have a Matrix
class:
public class Matrix { invert(); ... }
An instance of Matrix
must be wrapped with
stateCache
since the result depends on the matrix
state:
CacheWrapper cw = new CacheWrapper(); a_matrix.wrap(cw, "stateCache", "invert");
However, when the state of the matrix is modified, the cache
should be cleared since its values are not valid anymore. This can
be done by using the wrapping method clearCache
.
a_matrix.wrap(cw, "clearCache", new String[] { "set", "mul", "div", "add" } );
Field Summary | |
protected Vector |
cacheKeys
Store the keys for the cache. |
protected Vector |
cacheValues
Store the cached values. |
Fields inherited from class org.objectweb.jac.core.Wrapper |
ac |
Constructor Summary | |
CacheWrapper(AspectComponent ac)
|
Method Summary | |
Object |
clearCache(Interaction interaction)
Clear the cache. |
protected Object |
getCacheValue(int index)
Get a cached value. |
protected Object |
getCacheValue(Object[] key)
Get the memorized value of the method when called with the given (method, args) key. |
protected int |
isCacheHit(Object[] key)
Returns the index of a key in the cache, -1 if not found. |
protected void |
setCacheValue(Object[] key,
Object value)
Add a (method, args) key and its value into the cache. |
Object |
stateCache(Interaction interaction)
This wrapping method seeks in the cache wether the triple (wrappe, method, args) has already been called on the wrappee object when wrappee was in the same state. |
Object |
statelessCache(Interaction interaction)
This wrapping method seeks in the cache wether the couple (method, args) has already been called on the wrappee object. |
Methods inherited from class org.objectweb.jac.core.Wrapper |
attr, attrdef, defines, getAspectComponent, getAspectComponentName, getExceptionHandlers, proceed, setAspectComponent, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Vector cacheKeys
protected Vector cacheValues
Constructor Detail |
public CacheWrapper(AspectComponent ac)
Method Detail |
public Object statelessCache(Interaction interaction)
This wrapper can be used on objects that have complex, but
state independant computation to perform. For instance,
cache
could wrap a computational object that would
be able to invert a matrix so that the inversion of a given
matrix would be done only once.
NOTE: if the wrappee function depends on the the object
state the values returned by the statelessCache
will be wrong. In this case, use the
stateCache(Interaction)
public Object stateCache(Interaction interaction)
This wrapper can be used on objects that have complex state
dependant computation to perform. For instance,
cache
could wrap the invert method of a matrix
object. If you invert this matrix three times, then the third
inversion result will be found in the cache.
NOTE: if the wrappee method computation does not depend on
the wrappee state, then you should use the
statelessCache
method for better performance and
hits rate.
statelessCache(Interaction)
public Object clearCache(Interaction interaction)
This method should wrap all the methods that change the state of the wrappee in a case of a state cache.
protected void setCacheValue(Object[] key, Object value)
key
- the key to find the value in the cachevalue
- the cached valuegetCacheValue(Object[])
protected Object getCacheValue(Object[] key)
key
- the key
setCacheValue(Object[],Object)
protected Object getCacheValue(int index)
index
- the index in the cache
protected int isCacheHit(Object[] key)
key
- a complex key
|
Contact JAC development team: Renaud Pawlak Lionel Seinturier Laurent Martelli |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |