public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperationSource implements java.io.Serializable
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
.
Modifier and Type | Class and Description |
---|---|
protected static interface |
AnnotationCacheOperationSource.CacheOperationProvider
Callback interface providing
CacheOperation instance(s) based on
a given CacheAnnotationParser . |
Modifier and Type | Field and Description |
---|---|
private java.util.Set<CacheAnnotationParser> |
annotationParsers |
private boolean |
publicMethodsOnly |
logger
Constructor and Description |
---|
AnnotationCacheOperationSource()
Create a default AnnotationCacheOperationSource, supporting public methods
that carry the
Cacheable and CacheEvict annotations. |
AnnotationCacheOperationSource(boolean publicMethodsOnly)
Create a default
AnnotationCacheOperationSource , supporting public methods
that carry the Cacheable and CacheEvict annotations. |
AnnotationCacheOperationSource(CacheAnnotationParser... annotationParsers)
Create a custom AnnotationCacheOperationSource.
|
AnnotationCacheOperationSource(CacheAnnotationParser annotationParser)
Create a custom AnnotationCacheOperationSource.
|
AnnotationCacheOperationSource(java.util.Set<CacheAnnotationParser> annotationParsers)
Create a custom AnnotationCacheOperationSource.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
allowPublicMethodsOnly()
By default, only public methods can be made cacheable.
|
protected java.util.Collection<CacheOperation> |
determineCacheOperations(AnnotationCacheOperationSource.CacheOperationProvider provider)
Determine the cache operation(s) for the given
AnnotationCacheOperationSource.CacheOperationProvider . |
boolean |
equals(java.lang.Object other) |
protected java.util.Collection<CacheOperation> |
findCacheOperations(java.lang.Class<?> clazz)
Subclasses need to implement this to return the caching attribute for the
given class, if any.
|
protected java.util.Collection<CacheOperation> |
findCacheOperations(java.lang.reflect.Method method)
Subclasses need to implement this to return the caching attribute for the
given method, if any.
|
int |
hashCode() |
boolean |
isCandidateClass(java.lang.Class<?> targetClass)
Determine whether the given class is a candidate for cache operations
in the metadata format of this
CacheOperationSource . |
getCacheKey, getCacheOperations
private final boolean publicMethodsOnly
private final java.util.Set<CacheAnnotationParser> annotationParsers
public AnnotationCacheOperationSource()
Cacheable
and CacheEvict
annotations.public AnnotationCacheOperationSource(boolean publicMethodsOnly)
AnnotationCacheOperationSource
, supporting public methods
that carry the Cacheable
and CacheEvict
annotations.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)public AnnotationCacheOperationSource(CacheAnnotationParser annotationParser)
annotationParser
- the CacheAnnotationParser to usepublic AnnotationCacheOperationSource(CacheAnnotationParser... annotationParsers)
annotationParsers
- the CacheAnnotationParser to usepublic AnnotationCacheOperationSource(java.util.Set<CacheAnnotationParser> annotationParsers)
annotationParsers
- the CacheAnnotationParser to usepublic boolean isCandidateClass(java.lang.Class<?> targetClass)
CacheOperationSource
CacheOperationSource
.
If this method returns false
, the methods on the given class
will not get traversed for CacheOperationSource.getCacheOperations(java.lang.reflect.Method, java.lang.Class<?>)
introspection.
Returning false
is therefore an optimization for non-affected
classes, whereas true
simply means that the class needs to get
fully introspected for each method on the given class individually.
isCandidateClass
in interface CacheOperationSource
targetClass
- the class to introspectfalse
if the class is known to have no cache operation
metadata at class or method level; true
otherwise. The default
implementation returns true
, leading to regular introspection.@Nullable protected java.util.Collection<CacheOperation> findCacheOperations(java.lang.Class<?> clazz)
AbstractFallbackCacheOperationSource
findCacheOperations
in class AbstractFallbackCacheOperationSource
clazz
- the class to retrieve the attribute fornull
if none@Nullable protected java.util.Collection<CacheOperation> findCacheOperations(java.lang.reflect.Method method)
AbstractFallbackCacheOperationSource
findCacheOperations
in class AbstractFallbackCacheOperationSource
method
- the method to retrieve the attribute fornull
if none@Nullable protected java.util.Collection<CacheOperation> determineCacheOperations(AnnotationCacheOperationSource.CacheOperationProvider provider)
AnnotationCacheOperationSource.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.
provider
- the cache operation provider to usenull
if none foundprotected boolean allowPublicMethodsOnly()
allowPublicMethodsOnly
in class AbstractFallbackCacheOperationSource
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object