org.springframework.cache.interceptor

## 类 CacheAspectSupport

- java.lang.Object
- - org.springframework.cache.interceptor.AbstractCacheInvoker
  - - org.springframework.cache.interceptor.CacheAspectSupport

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton
  直接已知子类:
    CacheInterceptor

      public abstract class CacheAspectSupport
      extends AbstractCacheInvoker
      implements org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton

  Base class for caching aspects, such as the `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 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.

  从以下版本开始:
    3.1
  作者:
    Costin Leau, Juergen Hoeller, Chris Beams, Phillip Webb, Sam Brannen, Stephane Nicoll

- - ### 嵌套类概要

    嵌套类
    限定符和类型 | 类和说明
    --- | ---
    `protected class` | `CacheAspectSupport.CacheOperationContext` A `CacheOperationInvocationContext` context for a `CacheOperation`.
    `protected static class` | `CacheAspectSupport.CacheOperationMetadata` Metadata of a cache operation that does not depend on a particular invocation which makes it a good candidate for caching.

  - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `protected Log` | `logger`

  - ### 构造器概要

    构造器
    构造器和说明
    `CacheAspectSupport()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `afterPropertiesSet()`
    `void` | `afterSingletonsInstantiated()`
    `protected void` | `clearMetadataCache()` Clear the cached metadata.
    `protected Object` | `execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args)`
    `protected <T> T` | `getBean(String beanName, Class<T> expectedType)` Return a bean with the specified name and type.
    `protected CacheAspectSupport.CacheOperationMetadata` | `getCacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass)` Return the `CacheAspectSupport.CacheOperationMetadata` for the specified operation.
    `CacheOperationSource` | `getCacheOperationSource()` Return the CacheOperationSource for this cache aspect.
    `CacheResolver` | `getCacheResolver()` Return the default `CacheResolver` that this cache aspect delegates to.
    `protected Collection<? extends Cache>` | `getCaches(CacheOperationInvocationContext<CacheOperation> context, CacheResolver cacheResolver)`
    `KeyGenerator` | `getKeyGenerator()` Return the default `KeyGenerator` that this cache aspect delegates to.
    `protected CacheAspectSupport.CacheOperationContext` | `getOperationContext(CacheOperation operation, Method method, Object[] args, Object target, Class<?> targetClass)`
    `protected Object` | `invokeOperation(CacheOperationInvoker invoker)` Execute the underlying operation (typically in case of cache miss) and return the result of the invocation.
    `protected String` | `methodIdentification(Method method, Class<?> targetClass)` Convenience method to return a String representation of this Method for use in logging.
    `void` | `setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)` Set the containing `BeanFactory` for `CacheManager` and other service lookups.
    `void` | `setCacheManager(CacheManager cacheManager)` Set the `CacheManager` to use to create a default `CacheResolver`.
    `void` | `setCacheOperationSources(CacheOperationSource... cacheOperationSources)` Set one or more cache operation sources which are used to find the cache attributes.
    `void` | `setCacheResolver(CacheResolver cacheResolver)` Set the default `CacheResolver` that this cache aspect should delegate to if no specific cache resolver has been set for the operation.
    `void` | `setKeyGenerator(KeyGenerator keyGenerator)` Set the default `KeyGenerator` that this cache aspect should delegate to if no specific key generator has been set for the operation.

    - ### 从类继承的方法 org.springframework.cache.interceptor.AbstractCacheInvoker

      `doClear, doEvict, doGet, doPut, getErrorHandler, setErrorHandler`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 字段详细资料

    - #### logger

          protected final Log logger

  - ### 构造器详细资料

    - #### CacheAspectSupport

          public CacheAspectSupport()

  - ### 方法详细资料

    - #### setCacheOperationSources

          public void setCacheOperationSources(CacheOperationSource... cacheOperationSources)

      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 a `CompositeCacheOperationSource`.

    - #### getCacheOperationSource

          @Nullable
          public CacheOperationSource getCacheOperationSource()

      Return the CacheOperationSource for this cache aspect.

    - #### setKeyGenerator

          public void setKeyGenerator(KeyGenerator keyGenerator)

      Set the default `KeyGenerator` that this cache aspect should delegate to if no specific key generator has been set for the operation.

      The default is a `SimpleKeyGenerator`.

    - #### getKeyGenerator

          public KeyGenerator getKeyGenerator()

      Return the default `KeyGenerator` that this cache aspect delegates to.

    - #### setCacheResolver

          public void setCacheResolver(@Nullable
                                       CacheResolver cacheResolver)

      Set the default `CacheResolver` that 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.

      另请参阅:
        `setCacheManager(org.springframework.cache.CacheManager)`, `SimpleCacheResolver`

    - #### getCacheResolver

          @Nullable
          public CacheResolver getCacheResolver()

      Return the default `CacheResolver` that this cache aspect delegates to.

    - #### setCacheManager

          public void setCacheManager(CacheManager cacheManager)

      Set the `CacheManager` to use to create a default `CacheResolver`. Replace the current `CacheResolver`, if any.
      另请参阅:
        `setCacheResolver(org.springframework.cache.interceptor.CacheResolver)`, `SimpleCacheResolver`

    - #### setBeanFactory

          public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)

      Set the containing `BeanFactory` for `CacheManager` and other service lookups.
      指定者:
        `setBeanFactory` 在接口中 `org.springframework.beans.factory.BeanFactoryAware`
      从以下版本开始:
        4.3

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      指定者:
        `afterPropertiesSet` 在接口中 `org.springframework.beans.factory.InitializingBean`

    - #### afterSingletonsInstantiated

          public void afterSingletonsInstantiated()

      指定者:
        `afterSingletonsInstantiated` 在接口中 `org.springframework.beans.factory.SmartInitializingSingleton`

    - #### methodIdentification

          protected String methodIdentification(Method method,
                                                Class<?> targetClass)

      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 in
        `targetClass` - 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 the `CacheAspectSupport.CacheOperationMetadata` for the specified operation.

      Resolve the `CacheResolver` and the `KeyGenerator` to be used for the operation.

      参数:
        `operation` - the operation
        `method` - the method on which the operation is invoked
        `targetClass` - the target type
      返回:
        the resolved metadata for the operation

    - #### getBean

          protected <T> T getBean(String beanName,
                                  Class<T> expectedType)

      Return a bean with the specified name and type. Used to resolve services that are referenced by name in a `CacheOperation`.
      参数:
        `beanName` - the name of the bean, as defined by the operation
        `expectedType` - type for the bean
      返回:
        the bean matching that name
      抛出:
        `org.springframework.beans.factory.NoSuchBeanDefinitionException` - if such bean does not exist
      另请参阅:
        `CacheOperation.getKeyGenerator()`, `CacheOperation.getCacheManager()`, `CacheOperation.getCacheResolver()`

    - #### clearMetadataCache

          protected void clearMetadataCache()

      Clear the cached metadata.

    - #### execute

          @Nullable
          protected Object execute(CacheOperationInvoker invoker,
                                              Object target,
                                              Method method,
                                              Object[] args)

    - #### invokeOperation

          protected Object invokeOperation(CacheOperationInvoker invoker)

      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 a `CacheOperationInvoker.ThrowableWrapper`: the exception can be handled or modified but it must be wrapped in a `CacheOperationInvoker.ThrowableWrapper` as well.
      参数:
        `invoker` - the invoker handling the operation being cached
      返回:
        the result of the invocation
      另请参阅:
        `CacheOperationInvoker.invoke()`