org.wanghy.cache.key
Class HashCodeCacheKeyGenerator

java.lang.Object
  extended byorg.wanghy.cache.key.HashCodeCacheKeyGenerator
All Implemented Interfaces:
CacheKeyGenerator

public class HashCodeCacheKeyGenerator
extends Object
implements CacheKeyGenerator

Generates the key for a cache entry using the hashCode of the intercepted method and its arguments.

Version:
$Revision: 1.5 $ $Date: 2005/03/03 02:18:11 $
Author:
Alex Ruiz

Field Summary
private  boolean generateArgumentHashCode
          Flag that indicates if this generator should generate the hash code of the arguments passed to the method to apply caching to.
 
Constructor Summary
HashCodeCacheKeyGenerator()
          Constructor.
HashCodeCacheKeyGenerator(boolean generateArgumentHashCode)
          Constructor.
 
Method Summary
 CacheKey generateKey(MethodInvocation methodInvocation)
          Generates the key for a cache entry.
protected  int getMethodArgumentHashCode(Object methodArgument)
          Returns the hash code of the specified method argument.
 void setGenerateArgumentHashCode(boolean generateArgumentHashCode)
          Setter for the field generateArgumentHashCode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

generateArgumentHashCode

private boolean generateArgumentHashCode
Flag that indicates if this generator should generate the hash code of the arguments passed to the method to apply caching to. If false, this generator uses the default hash code of the arguments.

Constructor Detail

HashCodeCacheKeyGenerator

public HashCodeCacheKeyGenerator()
Constructor.


HashCodeCacheKeyGenerator

public HashCodeCacheKeyGenerator(boolean generateArgumentHashCode)
Constructor.

Parameters:
generateArgumentHashCode - the new value for generateArgumentHashCode.
Method Detail

generateKey

public final CacheKey generateKey(MethodInvocation methodInvocation)
Description copied from interface: CacheKeyGenerator
Generates the key for a cache entry.

Specified by:
generateKey in interface CacheKeyGenerator
Parameters:
methodInvocation - the description of an invocation to the intercepted method.
Returns:
the key for a cache entry.
See Also:
CacheKeyGenerator.generateKey(MethodInvocation)

getMethodArgumentHashCode

protected final int getMethodArgumentHashCode(Object methodArgument)
Returns the hash code of the specified method argument.

Parameters:
methodArgument - the method argument.
Returns:
the hash code of the specified method argument.

setGenerateArgumentHashCode

public final void setGenerateArgumentHashCode(boolean generateArgumentHashCode)
Setter for the field generateArgumentHashCode.

Parameters:
generateArgumentHashCode - the new value to set


Copyright © 2004-2005 Alex Ruiz. All Rights Reserved.