Top Description Fields Constructors Methods
org.springframework.cache.interceptor

public abstract Class AbstractFallbackCacheOperationSource

extends Object
implements CacheOperationSource
Class Inheritance
All Implemented Interfaces
org.springframework.cache.interceptor.CacheOperationSource
Known Direct Subclasses
org.springframework.cache.annotation.AnnotationCacheOperationSource
Imports
java.lang.reflect.Method, .Modifier, java.util.Collection, .Collections, .Map, java.util.concurrent.ConcurrentHashMap, org.apache.commons.logging.Log, .LogFactory, org.springframework.aop.support.AopUtils, org.springframework.core.MethodClassKey, org.springframework.lang.Nullable, org.springframework.util.ClassUtils

Abstract implementation of CacheOperation that caches attributes for methods and implements a fallback policy: 1. specific target method; 2. target class; 3. declaring method; 4. declaring class/interface.

Defaults to using the target class's caching attribute if none is associated with the target method. Any caching attribute associated with the target method completely overrides a class caching attribute. If none found on the target class, the interface that the invoked method has been called through (in case of a JDK proxy) will be checked.

This implementation caches attributes by method after they are first used. If it is ever desirable to allow dynamic changing of cacheable attributes (which is very unlikely), caching could be made configurable.

Authors
Costin Leau, Juergen Hoeller
Since
3.1

Field Summary

Modifier and TypeField and Description
private final Map<Object, Collection<CacheOperation>>
attributeCache

Cache of CacheOperations, keyed by method on a specific target class.

protected final Log
logger

Logger available to subclasses.

private static final Collection<CacheOperation>
NULL_CACHING_ATTRIBUTE

Canonical value held in cache to indicate no caching attribute was found for this method and we don't need to look again.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean
allowPublicMethodsOnly()

Should only public methods be allowed to have caching semantics?

private Collection<CacheOperation>
computeCacheOperations(Method method, Class<?> targetClass)

protected abstract Collection<CacheOperation>

Returns:

all caching attribute associated with this class, or null if none
findCacheOperations
(Class<?>
the class to retrieve the attribute for
clazz
)

Subclasses need to implement this to return the caching attribute for the given class, if any.

protected abstract Collection<CacheOperation>

Returns:

all caching attribute associated with this method, or null if none
findCacheOperations
(Method
the method to retrieve the attribute for
method
)

Subclasses need to implement this to return the caching attribute for the given method, if any.

protected Object

Returns:

the cache key (never null)
getCacheKey
(Method
the method (never null)
method
,
Class<?>
the target class (may be null)
targetClass
)

Determine a cache key for the given method and target class.

public Collection<CacheOperation>

Returns:

CacheOperation for this method, or null if the method is not cacheable
getCacheOperations
(Method
the method for the current invocation (never null)
method
,
Class<?>
the target class for this invocation (may be null)
targetClass
)

Implements org.springframework.cache.interceptor.CacheOperationSource.getCacheOperations.

Determine the caching attribute for this method invocation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeCacheback to summary
private final Map<Object, Collection<CacheOperation>> attributeCache

Cache of CacheOperations, keyed by method on a specific target class.

As this base class is not marked Serializable, the cache will be recreated after serialization - provided that the concrete subclass is Serializable.

loggerback to summary
protected final Log logger

Logger available to subclasses.

As this base class is not marked Serializable, the logger will be recreated after serialization - provided that the concrete subclass is Serializable.

NULL_CACHING_ATTRIBUTEback to summary
private static final Collection<CacheOperation> NULL_CACHING_ATTRIBUTE

Canonical value held in cache to indicate no caching attribute was found for this method and we don't need to look again.

Constructor Detail

AbstractFallbackCacheOperationSourceback to summary
public AbstractFallbackCacheOperationSource()

Method Detail

allowPublicMethodsOnlyback to summary
protected boolean allowPublicMethodsOnly()

Should only public methods be allowed to have caching semantics?

The default implementation returns false.

computeCacheOperationsback to summary
private Collection<CacheOperation> computeCacheOperations(Method method, Class<?> targetClass)
Annotations
@Nullable
findCacheOperationsback to summary
protected abstract Collection<CacheOperation> findCacheOperations(Class<?> clazz)

Subclasses need to implement this to return the caching attribute for the given class, if any.

Parameters
clazz:Class<?>

the class to retrieve the attribute for

Returns:Collection<CacheOperation>

all caching attribute associated with this class, or null if none

Annotations
@Nullable
findCacheOperationsback to summary
protected abstract Collection<CacheOperation> findCacheOperations(Method method)

Subclasses need to implement this to return the caching attribute for the given method, if any.

Parameters
method:Method

the method to retrieve the attribute for

Returns:Collection<CacheOperation>

all caching attribute associated with this method, or null if none

Annotations
@Nullable
getCacheKeyback to summary
protected Object getCacheKey(Method method, Class<?> targetClass)

Determine a cache key for the given method and target class.

Must not produce same key for overloaded methods. Must produce same key for different instances of the same method.

Parameters
method:Method

the method (never null)

targetClass:Class<?>

the target class (may be null)

Returns:Object

the cache key (never null)

getCacheOperationsback to summary
public Collection<CacheOperation> getCacheOperations(Method method, Class<?> targetClass)

Implements org.springframework.cache.interceptor.CacheOperationSource.getCacheOperations.

Determine the caching attribute for this method invocation.

Defaults to the class's caching attribute if no method attribute is found.

Parameters
method:Method

the method for the current invocation (never null)

targetClass:Class<?>

the target class for this invocation (may be null)

Returns:Collection<CacheOperation>

CacheOperation for this method, or null if the method is not cacheable

Annotations
@Override
@Nullable