Class AnnotationCacheOperationSource
- java.lang.Object
- org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource
- org.springframework.cache.annotation.AnnotationCacheOperationSource
- All Implemented Interfaces:
Serializable
,CacheOperationSource
public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperationSource implements Serializable
Implementation of theCacheOperationSource
interface for working with caching metadata in annotation format.This class reads Spring's
Cacheable
,CachePut
andCacheEvict
annotations and exposes corresponding caching operation definition to Spring's cache infrastructure. This class may also serve as base class for a customCacheOperationSource
.- Since:
- 3.1
- Author:
- Costin Leau, Juergen Hoeller, Stephane Nicoll
- See Also:
- Serialized Form
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
AnnotationCacheOperationSource.CacheOperationProvider
Callback interface providingCacheOperation
instance(s) based on a givenCacheAnnotationParser
.
Field Summary
Fields inherited from class org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource
logger
Constructor Summary
Constructors Constructor Description AnnotationCacheOperationSource()
Create a default AnnotationCacheOperationSource, supporting public methods that carry theCacheable
andCacheEvict
annotations.AnnotationCacheOperationSource(boolean publicMethodsOnly)
Create a defaultAnnotationCacheOperationSource
, supporting public methods that carry theCacheable
andCacheEvict
annotations.AnnotationCacheOperationSource(Set<CacheAnnotationParser> annotationParsers)
Create a custom AnnotationCacheOperationSource.AnnotationCacheOperationSource(CacheAnnotationParser annotationParser)
Create a custom AnnotationCacheOperationSource.AnnotationCacheOperationSource(CacheAnnotationParser... annotationParsers)
Create a custom AnnotationCacheOperationSource.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
allowPublicMethodsOnly()
By default, only public methods can be made cacheable.protected Collection<CacheOperation>
determineCacheOperations(AnnotationCacheOperationSource.CacheOperationProvider provider)
Determine the cache operation(s) for the givenAnnotationCacheOperationSource.CacheOperationProvider
.boolean
equals(Object other)
protected 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.int
hashCode()
Methods inherited from class org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource
getCacheKey, getCacheOperations
Constructor Detail
AnnotationCacheOperationSource
public AnnotationCacheOperationSource()
Create a default AnnotationCacheOperationSource, supporting public methods that carry theCacheable
andCacheEvict
annotations.
AnnotationCacheOperationSource
public AnnotationCacheOperationSource(boolean publicMethodsOnly)
Create a defaultAnnotationCacheOperationSource
, supporting public methods that carry theCacheable
andCacheEvict
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)
AnnotationCacheOperationSource
public AnnotationCacheOperationSource(CacheAnnotationParser annotationParser)
Create a custom AnnotationCacheOperationSource.- Parameters:
annotationParser
- the CacheAnnotationParser to use
AnnotationCacheOperationSource
public AnnotationCacheOperationSource(CacheAnnotationParser... annotationParsers)
Create a custom AnnotationCacheOperationSource.- Parameters:
annotationParsers
- the CacheAnnotationParser to use
AnnotationCacheOperationSource
public AnnotationCacheOperationSource(Set<CacheAnnotationParser> annotationParsers)
Create a custom AnnotationCacheOperationSource.- Parameters:
annotationParsers
- the CacheAnnotationParser to use
Method Detail
findCacheOperations
protected Collection<CacheOperation> findCacheOperations(Class<?> clazz)
Description copied from class:AbstractFallbackCacheOperationSource
Subclasses need to implement this to return the caching attribute for the given class, if any.- Specified by:
findCacheOperations
in classAbstractFallbackCacheOperationSource
- Parameters:
clazz
- the class to retrieve the attribute for- Returns:
- all caching attribute associated with this class, or
null
if none
findCacheOperations
protected Collection<CacheOperation> findCacheOperations(Method method)
Description copied from class:AbstractFallbackCacheOperationSource
Subclasses need to implement this to return the caching attribute for the given method, if any.- Specified by:
findCacheOperations
in classAbstractFallbackCacheOperationSource
- Parameters:
method
- the method to retrieve the attribute for- Returns:
- all caching attribute associated with this method, or
null
if none
determineCacheOperations
protected Collection<CacheOperation> determineCacheOperations(AnnotationCacheOperationSource.CacheOperationProvider provider)
Determine the cache operation(s) for the givenAnnotationCacheOperationSource.CacheOperationProvider
.This implementation delegates to configured
CacheAnnotationParsers
for 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
null
if none found
allowPublicMethodsOnly
protected boolean allowPublicMethodsOnly()
By default, only public methods can be made cacheable.- Overrides:
allowPublicMethodsOnly
in classAbstractFallbackCacheOperationSource