类 CacheAspectSupport
java.lang.Object
cn.taketoday.cache.interceptor.AbstractCacheInvoker
cn.taketoday.cache.interceptor.CacheAspectSupport
- 所有已实现的接口:
Aware,BeanFactoryAware,InitializingBean,SmartInitializingSingleton
- 直接已知子类:
CacheInterceptor
public abstract class CacheAspectSupport
extends AbstractCacheInvoker
implements BeanFactoryAware, InitializingBean, SmartInitializingSingleton
Base class for caching aspects, such as the
CacheInterceptor or an
AspectJ aspect.
This enables the underlying Framework caching infrastructure to be used easily to implement an aspect for any aspect system.
Subclasses are responsible for calling relevant methods in the correct order.
Uses the Strategy design pattern. A CacheOperationSource is
used for determining caching operations, a KeyGenerator will build the
cache keys, and a CacheResolver will resolve the actual cache(s) to use.
Note: A cache aspect is serializable but does not perform any actual caching after deserialization.
- 从以下版本开始:
- 4.0
- 作者:
- Costin Leau, Juergen Hoeller, Chris Beams, Phillip Webb, Sam Brannen, Stephane Nicoll
-
嵌套类概要
嵌套类修饰符和类型类说明protected classACacheOperationInvocationContextcontext for aCacheOperation.protected static classMetadata of a cache operation that does not depend on a particular invocation which makes it a good candidate for caching. -
字段概要
从类继承的字段 cn.taketoday.cache.interceptor.AbstractCacheInvoker
errorHandler -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidvoidprotected voidClear the cached metadata.voidconfigure(Supplier<CacheErrorHandler> errorHandler, Supplier<KeyGenerator> keyGenerator, Supplier<CacheResolver> cacheResolver, Supplier<CacheManager> cacheManager) Configure this aspect with the given error handler, key generator and cache resolver/manager suppliers, applying the corresponding default if a supplier is not resolvable.protected Objectexecute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) protected <T> TReturn a bean with the specified name and type.getCacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass) Return theCacheAspectSupport.CacheOperationMetadatafor the specified operation.Return the CacheOperationSource for this cache aspect.Return the defaultCacheResolverthat this cache aspect delegates to.protected Collection<? extends Cache>getCaches(CacheOperationInvocationContext<CacheOperation> context, CacheResolver cacheResolver) Return the defaultKeyGeneratorthat this cache aspect delegates to.protected CacheAspectSupport.CacheOperationContextgetOperationContext(CacheOperation operation, Method method, Object[] args, Object target, Class<?> targetClass) protected ObjectinvokeOperation(CacheOperationInvoker invoker) Execute the underlying operation (typically in case of cache miss) and return the result of the invocation.protected StringmethodIdentification(Method method, Class<?> targetClass) Convenience method to return a String representation of this Method for use in logging.voidsetBeanFactory(BeanFactory beanFactory) Set the containingBeanFactoryforCacheManagerand other service lookups.voidsetCacheManager(CacheManager cacheManager) Set theCacheManagerto use to create a defaultCacheResolver.voidsetCacheOperationSource(CacheOperationSource cacheOperationSource) Set the CacheOperationSource for this cache aspect.voidsetCacheOperationSources(CacheOperationSource... cacheOperationSources) Set one or more cache operation sources which are used to find the cache attributes.voidsetCacheResolver(CacheResolver cacheResolver) Set the defaultCacheResolverthat this cache aspect should delegate to if no specific cache resolver has been set for the operation.voidsetKeyGenerator(KeyGenerator keyGenerator) Set the defaultKeyGeneratorthat this cache aspect should delegate to if no specific key generator has been set for the operation.从类继承的方法 cn.taketoday.cache.interceptor.AbstractCacheInvoker
doClear, doEvict, doGet, doPut, getErrorHandler, setErrorHandler
-
构造器详细资料
-
CacheAspectSupport
public CacheAspectSupport()
-
-
方法详细资料
-
configure
public void configure(@Nullable Supplier<CacheErrorHandler> errorHandler, @Nullable Supplier<KeyGenerator> keyGenerator, @Nullable Supplier<CacheResolver> cacheResolver, @Nullable Supplier<CacheManager> cacheManager) Configure this aspect with the given error handler, key generator and cache resolver/manager suppliers, applying the corresponding default if a supplier is not resolvable. -
setCacheOperationSources
Set one or more cache operation sources which are used to find the cache attributes. If more than one source is provided, they will be aggregated using aCompositeCacheOperationSource. -
setCacheOperationSource
Set the CacheOperationSource for this cache aspect. -
getCacheOperationSource
Return the CacheOperationSource for this cache aspect. -
setKeyGenerator
Set the defaultKeyGeneratorthat this cache aspect should delegate to if no specific key generator has been set for the operation.The default is a
SimpleKeyGenerator. -
getKeyGenerator
Return the defaultKeyGeneratorthat this cache aspect delegates to. -
setCacheResolver
Set the defaultCacheResolverthat this cache aspect should delegate to if no specific cache resolver has been set for the operation.The default resolver resolves the caches against their names and the default cache manager.
-
getCacheResolver
Return the defaultCacheResolverthat this cache aspect delegates to. -
setCacheManager
Set theCacheManagerto use to create a defaultCacheResolver. Replace the currentCacheResolver, if any. -
setBeanFactory
Set the containingBeanFactoryforCacheManagerand other service lookups.- 指定者:
setBeanFactory在接口中BeanFactoryAware
-
afterPropertiesSet
public void afterPropertiesSet()- 指定者:
afterPropertiesSet在接口中InitializingBean
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated() -
methodIdentification
Convenience method to return a String representation of this Method for use in logging. Can be overridden in subclasses to provide a different identifier for the given method.- 参数:
method- the method we're interested intargetClass- class the method is on- 返回:
- log message identifying this method
- 另请参阅:
-
ClassUtils.getQualifiedMethodName(java.lang.reflect.Method)
-
getCaches
protected Collection<? extends Cache> getCaches(CacheOperationInvocationContext<CacheOperation> context, CacheResolver cacheResolver) -
getOperationContext
protected CacheAspectSupport.CacheOperationContext getOperationContext(CacheOperation operation, Method method, Object[] args, Object target, Class<?> targetClass) -
getCacheOperationMetadata
protected CacheAspectSupport.CacheOperationMetadata getCacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass) Return theCacheAspectSupport.CacheOperationMetadatafor the specified operation.Resolve the
CacheResolverand theKeyGeneratorto be used for the operation.- 参数:
operation- the operationmethod- the method on which the operation is invokedtargetClass- the target type- 返回:
- the resolved metadata for the operation
-
getBean
Return a bean with the specified name and type. Used to resolve services that are referenced by name in aCacheOperation.- 参数:
beanName- the name of the bean, as defined by the operationexpectedType- type for the bean- 返回:
- the bean matching that name
- 抛出:
NoSuchBeanDefinitionException- if such bean does not exist- 另请参阅:
-
clearMetadataCache
protected void clearMetadataCache()Clear the cached metadata. -
execute
@Nullable protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) -
invokeOperation
Execute the underlying operation (typically in case of cache miss) and return the result of the invocation. If an exception occurs it will be wrapped in aCacheOperationInvoker.ThrowableWrapper: the exception can be handled or modified but it must be wrapped in aCacheOperationInvoker.ThrowableWrapperas well.- 参数:
invoker- the invoker handling the operation being cached- 返回:
- the result of the invocation
- 另请参阅:
-