public abstract class CacheAspectSupport extends Object implements InitializingBean
CacheInterceptor
or an AspectJ aspect.
This enables the underlying Spring caching infrastructure to be used easily to implement an aspect for any aspect system.
Subclasses are responsible for calling methods in this class in the correct order.
Uses the Strategy design pattern. A CacheManager
implementation will perform the actual cache management, and a
CacheOperationSource
is used for determining caching
operations.
A cache aspect is serializable if its CacheManager
and
CacheOperationSource
are serializable.
Modifier and Type | Class and Description |
---|---|
protected class |
CacheAspectSupport.CacheOperationContext |
static interface |
CacheAspectSupport.Invoker |
Constructor and Description |
---|
CacheAspectSupport() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
protected Object |
execute(CacheAspectSupport.Invoker invoker,
Object target,
Method method,
Object[] args) |
CacheManager |
getCacheManager()
Return the CacheManager that this cache aspect delegates to.
|
CacheOperationSource |
getCacheOperationSource()
Return the CacheOperationSource for this cache aspect.
|
protected Collection<? extends Cache> |
getCaches(CacheOperation operation) |
KeyGenerator |
getKeyGenerator()
Return the KeyGenerator for this cache aspect,
|
protected CacheAspectSupport.CacheOperationContext |
getOperationContext(CacheOperation operation,
Method method,
Object[] args,
Object target,
Class<?> targetClass) |
protected String |
methodIdentification(Method method,
Class<?> targetClass)
Convenience method to return a String representation of this Method
for use in logging.
|
void |
setCacheManager(CacheManager cacheManager)
Set the CacheManager that this cache aspect should delegate to.
|
void |
setCacheOperationSources(CacheOperationSource... cacheOperationSources)
Set one or more cache operation sources which are used to find the cache
attributes.
|
void |
setKeyGenerator(KeyGenerator keyGenerator)
Set the KeyGenerator for this cache aspect.
|
protected final Log logger
public void setCacheManager(CacheManager cacheManager)
public CacheManager getCacheManager()
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources)
CompositeCacheOperationSource
.cacheOperationSources
- must not be null
public CacheOperationSource getCacheOperationSource()
public void setKeyGenerator(KeyGenerator keyGenerator)
SimpleKeyGenerator
.public KeyGenerator getKeyGenerator()
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
protected String methodIdentification(Method method, Class<?> targetClass)
method
- the method we're interested intargetClass
- class the method is onClassUtils.getQualifiedMethodName(java.lang.reflect.Method)
protected Collection<? extends Cache> getCaches(CacheOperation operation)
protected CacheAspectSupport.CacheOperationContext getOperationContext(CacheOperation operation, Method method, Object[] args, Object target, Class<?> targetClass)
protected Object execute(CacheAspectSupport.Invoker invoker, Object target, Method method, Object[] args)