org.springframework.cache.annotation
Class AnnotationCacheDefinitionSource

java.lang.Object
  extended by org.springframework.cache.interceptor.AbstractFallbackCacheDefinitionSource
      extended by org.springframework.cache.annotation.AnnotationCacheDefinitionSource
All Implemented Interfaces:
Serializable, CacheDefinitionSource

public class AnnotationCacheDefinitionSource
extends AbstractFallbackCacheDefinitionSource
implements Serializable

Implementation of the CacheDefinitionSource interface for working with caching metadata in JDK 1.5+ annotation format.

This class reads Spring's JDK 1.5+ Cacheable and CacheEvict annotations and exposes corresponding caching operation definition to Spring's cache infrastructure. This class may also serve as base class for a custom CacheDefinitionSource.

Author:
Costin Leau
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.springframework.cache.interceptor.AbstractFallbackCacheDefinitionSource
logger
 
Constructor Summary
AnnotationCacheDefinitionSource()
          Create a default AnnotationCacheOperationDefinitionSource, supporting public methods that carry the Cacheable and CacheInvalidate annotations.
AnnotationCacheDefinitionSource(boolean publicMethodsOnly)
          Create a custom AnnotationCacheOperationDefinitionSource, supporting public methods that carry the Cacheable and CacheInvalidate annotations.
AnnotationCacheDefinitionSource(CacheAnnotationParser... annotationParsers)
          Create a custom AnnotationCacheOperationDefinitionSource.
 
Method Summary
protected  boolean allowPublicMethodsOnly()
          By default, only public methods can be made cacheable.
protected  CacheDefinition determineCacheDefinition(AnnotatedElement ae)
          Determine the cache operation definition for the given method or class.
protected  CacheDefinition findCacheDefinition(Class<?> clazz)
          Subclasses need to implement this to return the caching attribute for the given class, if any.
protected  CacheDefinition findCacheOperation(Method method)
          Subclasses need to implement this to return the caching attribute for the given method, if any.
 
Methods inherited from class org.springframework.cache.interceptor.AbstractFallbackCacheDefinitionSource
getCacheDefinition, getCacheKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationCacheDefinitionSource

public AnnotationCacheDefinitionSource()
Create a default AnnotationCacheOperationDefinitionSource, supporting public methods that carry the Cacheable and CacheInvalidate annotations.


AnnotationCacheDefinitionSource

public AnnotationCacheDefinitionSource(boolean publicMethodsOnly)
Create a custom AnnotationCacheOperationDefinitionSource, supporting public methods that carry the Cacheable and CacheInvalidate annotations.

Parameters:
publicMethodsOnly - whether to support only annotated public methods typically for use with proxy-based AOP), or protected/private methods as well (typically used with AspectJ class weaving)

AnnotationCacheDefinitionSource

public AnnotationCacheDefinitionSource(CacheAnnotationParser... annotationParsers)
Create a custom AnnotationCacheOperationDefinitionSource.

Parameters:
annotationParsers - the CacheAnnotationParser to use
Method Detail

findCacheDefinition

protected CacheDefinition findCacheDefinition(Class<?> clazz)
Description copied from class: AbstractFallbackCacheDefinitionSource
Subclasses need to implement this to return the caching attribute for the given class, if any.

Specified by:
findCacheDefinition in class AbstractFallbackCacheDefinitionSource
Parameters:
clazz - the class to retrieve the attribute for
Returns:
all caching attribute associated with this class (or null if none)

findCacheOperation

protected CacheDefinition findCacheOperation(Method method)
Description copied from class: AbstractFallbackCacheDefinitionSource
Subclasses need to implement this to return the caching attribute for the given method, if any.

Specified by:
findCacheOperation in class AbstractFallbackCacheDefinitionSource
Parameters:
method - the method to retrieve the attribute for
Returns:
all caching attribute associated with this method (or null if none)

determineCacheDefinition

protected CacheDefinition determineCacheDefinition(AnnotatedElement ae)
Determine the cache operation definition for the given method or class.

This implementation delegates to configured CacheAnnotationParsers for parsing known annotations into Spring's metadata attribute class. Returns null if it's not cacheable.

Can be overridden to support custom annotations that carry caching metadata.

Parameters:
ae - the annotated method or class
Returns:
CacheOperationDefinition the configured caching operation, or null if none was found

allowPublicMethodsOnly

protected boolean allowPublicMethodsOnly()
By default, only public methods can be made cacheable.

Overrides:
allowPublicMethodsOnly in class AbstractFallbackCacheDefinitionSource