com.googlecode.ehcache.annotations.key
Class SpELCacheKeyGenerator

java.lang.Object
  extended by com.googlecode.ehcache.annotations.key.SpELCacheKeyGenerator
All Implemented Interfaces:
CacheKeyGenerator<java.io.Serializable>, ReflectionHelperAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean

public class SpELCacheKeyGenerator
extends java.lang.Object
implements CacheKeyGenerator<java.io.Serializable>, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, ReflectionHelperAware

Spring Expression Language cache key generator. Usage:

@Property(key="expression" value="args[ARGUMENT_INDEX].propertyOfModel"

Author:
Timothy Freyne

Constructor Summary
SpELCacheKeyGenerator()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  CacheKeyGenerator<java.io.Serializable> createKeyGenerator(java.lang.String name, java.lang.Class<CacheKeyGenerator<java.io.Serializable>> keyGeneratorClass, org.springframework.beans.MutablePropertyValues properties)
          Create a new key generator with the specified name.
protected  void createKeyGeneratorMethodExecutors()
          Add MethodExecutor wrapper around all of the registered CacheKeyGenerators to avoid creating the wrappers on every use.
 java.io.Serializable generateKey(org.aopalliance.intercept.MethodInvocation methodInvocation)
          Generates the key for a cache entry.
 java.io.Serializable generateKey(java.lang.Object... data)
          Generates the key for a cache entry.
protected  org.springframework.expression.EvaluationContext getEvaluationContext(org.aopalliance.intercept.MethodInvocation methodInvocation, java.lang.Object... args)
          Get the EvaluationContext to use to evaluate the configured Expression
protected  org.springframework.expression.Expression parseExpression(java.lang.String expression)
          Parse the specified String into a SpEL Expression
protected  void registerDefaultKeyGenerators()
          Check that all CacheKeyGenerators defined in the DEFAULT_KEY_GENERATORS Map are registered in the SpEL context as key functions.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
           
 void setExpression(java.lang.String expression)
          The SpEL Expression evaluated to generate the cache key.
 void setKeyGenerators(java.util.Map<java.lang.String,CacheKeyGenerator<java.io.Serializable>> keyGenerators)
          A Map of CacheKeyGenerators to register as functions on the #key object in the SpEL EvaluationContext.
 void setReflectionHelper(ReflectionHelper reflectionHelper)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpELCacheKeyGenerator

public SpELCacheKeyGenerator()
Method Detail

setExpression

public void setExpression(java.lang.String expression)
The SpEL Expression evaluated to generate the cache key. The expression must return a Serializable object


setKeyGenerators

public void setKeyGenerators(java.util.Map<java.lang.String,CacheKeyGenerator<java.io.Serializable>> keyGenerators)
A Map of CacheKeyGenerators to register as functions on the #key object in the SpEL EvaluationContext. The map key is used as the function name on the #key object.


setReflectionHelper

public void setReflectionHelper(ReflectionHelper reflectionHelper)
Specified by:
setReflectionHelper in interface ReflectionHelperAware

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
                    throws org.springframework.beans.BeansException
Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Throws:
org.springframework.beans.BeansException

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

registerDefaultKeyGenerators

protected final void registerDefaultKeyGenerators()
Check that all CacheKeyGenerators defined in the DEFAULT_KEY_GENERATORS Map are registered in the SpEL context as key functions.


createKeyGeneratorMethodExecutors

protected final void createKeyGeneratorMethodExecutors()
Add MethodExecutor wrapper around all of the registered CacheKeyGenerators to avoid creating the wrappers on every use.


createKeyGenerator

protected CacheKeyGenerator<java.io.Serializable> createKeyGenerator(java.lang.String name,
                                                                     java.lang.Class<CacheKeyGenerator<java.io.Serializable>> keyGeneratorClass,
                                                                     org.springframework.beans.MutablePropertyValues properties)
Create a new key generator with the specified name.


generateKey

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

Specified by:
generateKey in interface CacheKeyGenerator<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

generateKey

public java.io.Serializable generateKey(java.lang.Object... data)
Description copied from interface: CacheKeyGenerator
Generates the key for a cache entry.

Specified by:
generateKey in interface CacheKeyGenerator<java.io.Serializable>
Parameters:
data - the objects to use when generating the key
Returns:
the created key, will never be null and will be Serializable

parseExpression

protected org.springframework.expression.Expression parseExpression(java.lang.String expression)
Parse the specified String into a SpEL Expression


getEvaluationContext

protected org.springframework.expression.EvaluationContext getEvaluationContext(org.aopalliance.intercept.MethodInvocation methodInvocation,
                                                                                java.lang.Object... args)
Get the EvaluationContext to use to evaluate the configured Expression



Copyright © 2011. All Rights Reserved.