com.googlecode.ehcache.annotations.key
Class AbstractCacheKeyGenerator<T extends java.io.Serializable>

java.lang.Object
  extended by com.googlecode.ehcache.annotations.key.AbstractCacheKeyGenerator<T>
All Implemented Interfaces:
CacheKeyGenerator<T>
Direct Known Subclasses:
AbstractDeepCacheKeyGenerator, DelegateCacheKeyGenerator

public abstract class AbstractCacheKeyGenerator<T extends java.io.Serializable>
extends java.lang.Object
implements CacheKeyGenerator<T>

Base class for cache key generators. Handles common logic for including/excluding the method signature from key generation. Also provides support for avoiding circular references for key generators that traverse the argument object graph via the register(Object) and unregister(Object) APIs

Version:
$Revision: 656 $
Author:
Eric Dalquist

Constructor Summary
AbstractCacheKeyGenerator()
          Default constructor, same as calling AbstractCacheKeyGenerator(boolean, boolean) with (true, true)
AbstractCacheKeyGenerator(boolean includeMethod, boolean includeParameterTypes)
           
 
Method Summary
 T generateKey(org.aopalliance.intercept.MethodInvocation methodInvocation)
          Generates the key for a cache entry.
abstract  T generateKey(java.lang.Object... data)
          Called to generate the key.
 boolean isCheckforCycles()
           
 boolean isIncludeMethod()
           
 boolean isIncludeParameterTypes()
           
protected  boolean register(java.lang.Object element)
           Registers the given object.
 void setCheckforCycles(boolean checkforCycles)
          If the key generation should gracefully handle object graph cycles.
 void setIncludeMethod(boolean includeMethod)
          Determines if the invoked method signature should be included in the generated cache key.
 void setIncludeParameterTypes(boolean includeParameterTypes)
          Determines if the method parameter types returned by Method.getParameterTypes() should be included in the generated key.
protected  void unregister(java.lang.Object element)
           Unregisters the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCacheKeyGenerator

public AbstractCacheKeyGenerator()
Default constructor, same as calling AbstractCacheKeyGenerator(boolean, boolean) with (true, true)


AbstractCacheKeyGenerator

public AbstractCacheKeyGenerator(boolean includeMethod,
                                 boolean includeParameterTypes)
See Also:
setIncludeMethod(boolean), setIncludeParameterTypes(boolean)
Method Detail

isIncludeMethod

public final boolean isIncludeMethod()

setIncludeMethod

public final void setIncludeMethod(boolean includeMethod)
Determines if the invoked method signature should be included in the generated cache key. If true Method.getDeclaringClass(), Method.getName(), and Method.getReturnType() are included in the object array the key is generated from. Note that the effect of this option is such that two methods with the same arguments will have different keys if true. If you have two methods in the same class with the same name and return value you may want to enable setIncludeParameterTypes(boolean) for even more specific key generation. Note that including the method signature in key generation reduces key generation speed.

Parameters:
includeMethod - true If the Method from the MethodInvocation should be included in the generated key, defaults to true.
See Also:
setIncludeParameterTypes(boolean)

isIncludeParameterTypes

public final boolean isIncludeParameterTypes()

setIncludeParameterTypes

public final void setIncludeParameterTypes(boolean includeParameterTypes)
Determines if the method parameter types returned by Method.getParameterTypes() should be included in the generated key. This is broken out into a separate option because the call results in a clone() call on the Class[] every time Method.getParameterTypes() which reduces key generation speed. This is option is only used if setIncludeMethod(boolean) is true.

Parameters:
includeParameterTypes - true if the Method.getParameterTypes() should be included in the generated key, defaults to false.
See Also:
setIncludeMethod(boolean)

isCheckforCycles

public final boolean isCheckforCycles()

setCheckforCycles

public final void setCheckforCycles(boolean checkforCycles)
If the key generation should gracefully handle object graph cycles. If false the register(Object) and unregister(Object) methods are non-functional. If true the implementation of this class must correctly utilize the register(Object) and unregister(Object) methods to track visited objects.

Parameters:
checkforCycles - Defaults to false.

generateKey

public T generateKey(org.aopalliance.intercept.MethodInvocation methodInvocation)
Description copied from interface: CacheKeyGenerator
Generates the key for a cache entry.

Specified by:
generateKey in interface CacheKeyGenerator<T extends java.io.Serializable>
Parameters:
methodInvocation - the description of an invocation to the intercepted method.
Returns:
the created key, will never be null and will be Serializable

register

protected final boolean register(java.lang.Object element)

Registers the given object. Used by the reflection methods to avoid infinite loops.

Parameters:
element - The object to register.
Returns:
true if the object is not currently registered

unregister

protected final void unregister(java.lang.Object element)

Unregisters the given object. Used by the reflection methods to avoid infinite loops.


generateKey

public abstract T generateKey(java.lang.Object... data)
Called to generate the key. Depending on the setIncludeMethod(boolean) and setIncludeParameterTypes(boolean) the the appropriate parts of the Method signature will be included in the data array.

Specified by:
generateKey in interface CacheKeyGenerator<T extends java.io.Serializable>
Parameters:
data - the objects to use when generating the key
Returns:
The Serializable cache key for the method invocation.


Copyright © 2011. All Rights Reserved.