Class AnnotationCacheOperationSource
- All Implemented Interfaces:
- Serializable,- CacheOperationSource
CacheOperationSource interface for working with caching metadata in annotation format.
 This class reads Spring's Cacheable, CachePut 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
 CacheOperationSource.
- Since:
- 3.1
- Author:
- Costin Leau, Juergen Hoeller, Stephane Nicoll
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static interfaceCallback interface providingCacheOperationinstance(s) based on a givenCacheAnnotationParser.
- 
Field SummaryFields inherited from class org.springframework.cache.interceptor.AbstractFallbackCacheOperationSourcelogger
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a default AnnotationCacheOperationSource, supporting public methods that carry theCacheableandCacheEvictannotations.AnnotationCacheOperationSource(boolean publicMethodsOnly) Create a defaultAnnotationCacheOperationSource, supporting public methods that carry theCacheableandCacheEvictannotations.AnnotationCacheOperationSource(Set<CacheAnnotationParser> annotationParsers) Create a custom AnnotationCacheOperationSource.AnnotationCacheOperationSource(CacheAnnotationParser annotationParser) Create a custom AnnotationCacheOperationSource.AnnotationCacheOperationSource(CacheAnnotationParser... annotationParsers) Create a custom AnnotationCacheOperationSource.
- 
Method SummaryModifier and TypeMethodDescriptionprotected booleanBy default, only public methods can be made cacheable.protected Collection<CacheOperation>Determine the cache operation(s) for the givenAnnotationCacheOperationSource.CacheOperationProvider.booleanprotected Collection<CacheOperation>findCacheOperations(Class<?> clazz) Subclasses need to implement this to return the caching attribute for the given class, if any.protected Collection<CacheOperation>findCacheOperations(Method method) Subclasses need to implement this to return the caching attribute for the given method, if any.inthashCode()booleanisCandidateClass(Class<?> targetClass) Determine whether the given class is a candidate for cache operations in the metadata format of thisCacheOperationSource.Methods inherited from class org.springframework.cache.interceptor.AbstractFallbackCacheOperationSourcegetCacheKey, getCacheOperations
- 
Constructor Details- 
AnnotationCacheOperationSourcepublic AnnotationCacheOperationSource()Create a default AnnotationCacheOperationSource, supporting public methods that carry theCacheableandCacheEvictannotations.
- 
AnnotationCacheOperationSourcepublic AnnotationCacheOperationSource(boolean publicMethodsOnly) Create a defaultAnnotationCacheOperationSource, supporting public methods that carry theCacheableandCacheEvictannotations.- 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)
 
- 
AnnotationCacheOperationSourceCreate a custom AnnotationCacheOperationSource.- Parameters:
- annotationParser- the CacheAnnotationParser to use
 
- 
AnnotationCacheOperationSourceCreate a custom AnnotationCacheOperationSource.- Parameters:
- annotationParsers- the CacheAnnotationParser to use
 
- 
AnnotationCacheOperationSourceCreate a custom AnnotationCacheOperationSource.- Parameters:
- annotationParsers- the CacheAnnotationParser to use
 
 
- 
- 
Method Details- 
isCandidateClassDescription copied from interface:CacheOperationSourceDetermine whether the given class is a candidate for cache operations in the metadata format of thisCacheOperationSource.If this method returns false, the methods on the given class will not get traversed forCacheOperationSource.getCacheOperations(java.lang.reflect.Method, java.lang.Class<?>)introspection. Returningfalseis therefore an optimization for non-affected classes, whereastruesimply means that the class needs to get fully introspected for each method on the given class individually.- Specified by:
- isCandidateClassin interface- CacheOperationSource
- Parameters:
- targetClass- the class to introspect
- Returns:
- falseif the class is known to have no cache operation metadata at class or method level;- trueotherwise. The default implementation returns- true, leading to regular introspection.
 
- 
findCacheOperationsDescription copied from class:AbstractFallbackCacheOperationSourceSubclasses need to implement this to return the caching attribute for the given class, if any.- Specified by:
- findCacheOperationsin class- AbstractFallbackCacheOperationSource
- Parameters:
- clazz- the class to retrieve the attribute for
- Returns:
- all caching attribute associated with this class, or nullif none
 
- 
findCacheOperationsDescription copied from class:AbstractFallbackCacheOperationSourceSubclasses need to implement this to return the caching attribute for the given method, if any.- Specified by:
- findCacheOperationsin class- AbstractFallbackCacheOperationSource
- Parameters:
- method- the method to retrieve the attribute for
- Returns:
- all caching attribute associated with this method, or nullif none
 
- 
determineCacheOperations@Nullable protected Collection<CacheOperation> determineCacheOperations(AnnotationCacheOperationSource.CacheOperationProvider provider) Determine the cache operation(s) for the givenAnnotationCacheOperationSource.CacheOperationProvider.This implementation delegates to configured CacheAnnotationParsersfor parsing known annotations into Spring's metadata attribute class.Can be overridden to support custom annotations that carry caching metadata. - Parameters:
- provider- the cache operation provider to use
- Returns:
- the configured caching operations, or nullif none found
 
- 
allowPublicMethodsOnlyprotected boolean allowPublicMethodsOnly()By default, only public methods can be made cacheable.- Overrides:
- allowPublicMethodsOnlyin class- AbstractFallbackCacheOperationSource
 
- 
equals
- 
hashCodepublic int hashCode()
 
-