public abstract class CacheAspectSupport extends AbstractCacheInvoker implements BeanFactoryAware, InitializingBean, SmartInitializingSingleton
CacheInterceptor や AspectJ アスペクトなど、アスペクトをキャッシュするための基本クラス。これにより、基になる Spring キャッシングインフラストラクチャを簡単に使用して、任意のアスペクトシステムのアスペクトを実装できます。
サブクラスは、関連するメソッドを正しい順序で呼び出す責任があります。
戦略設計パターンを使用します。CacheOperationSource はキャッシュ操作の決定に使用され、KeyGenerator はキャッシュキーを構築し、CacheResolver は実際に使用するキャッシュを解決します。
メモ: キャッシュアスペクトは直列化可能ですが、逆直列化後に実際のキャッシュを実行しません。
| 修飾子と型 | クラスと説明 |
|---|---|
protected class | CacheAspectSupport.CacheOperationContext |
protected static class | CacheAspectSupport.CacheOperationMetadata 特定の呼び出しに依存しないキャッシュ操作のメタデータは、キャッシュの適切な候補になります。 |
| 修飾子と型 | フィールドと説明 |
|---|---|
protected Log | logger |
errorHandler| コンストラクターと説明 |
|---|
CacheAspectSupport() |
| 修飾子と型 | メソッドと説明 |
|---|---|
void | afterPropertiesSet() |
void | afterSingletonsInstantiated() シングルトン事前インスタンス化フェーズの終わりに呼び出され、すべての通常のシングルトン Bean がすでに作成されていることを保証します。 |
protected void | clearMetadataCache() キャッシュされたメタデータをクリアします。 |
void | configure(SupplierSE<CacheErrorHandler> errorHandler, SupplierSE<KeyGenerator> keyGenerator, SupplierSE<CacheResolver> cacheResolver, SupplierSE<CacheManager> cacheManager) 指定されたエラーハンドラー、キージェネレーター、キャッシュリゾルバー / マネージャーのサプライヤーでこのアスペクトを設定し、サプライヤーが解決できない場合は対応するデフォルトを適用します。 |
protected ObjectSE | execute(CacheOperationInvoker invoker, ObjectSE target, MethodSE method, ObjectSE[] args) |
protected <T> T | getBean(StringSE beanName, ClassSE<T> expectedType) 指定された名前と型の Bean を返します。 |
protected CacheAspectSupport.CacheOperationMetadata | getCacheOperationMetadata(CacheOperation operation, MethodSE method, ClassSE<?> targetClass) 指定された操作の CacheAspectSupport.CacheOperationMetadata を返します。 |
CacheOperationSource | getCacheOperationSource() このキャッシュアスペクトの CacheOperationSource を返します。 |
CacheResolver | getCacheResolver() このキャッシュアスペクトが委譲するデフォルトの CacheResolver を返します。 |
protected CollectionSE<? extends Cache> | getCaches(CacheOperationInvocationContext<CacheOperation> context, CacheResolver cacheResolver) |
KeyGenerator | getKeyGenerator() このキャッシュアスペクトが委譲するデフォルトの KeyGenerator を返します。 |
protected CacheAspectSupport.CacheOperationContext | getOperationContext(CacheOperation operation, MethodSE method, ObjectSE[] args, ObjectSE target, ClassSE<?> targetClass) |
protected ObjectSE | invokeOperation(CacheOperationInvoker invoker) 基本的な操作を実行し(通常はキャッシュミスの場合)、呼び出しの結果を返します。 |
protected StringSE | methodIdentification(MethodSE method, ClassSE<?> targetClass) ロギングで使用するためにこのメソッドの文字列表現を返す簡易メソッド。 |
void | setBeanFactory(BeanFactory beanFactory) 含まれている BeanFactory を CacheManager およびその他のサービス検索用に設定します。 |
void | setCacheManager(CacheManager cacheManager) デフォルト CacheResolver の作成に使用する CacheManager を設定します。 |
void | setCacheOperationSource(CacheOperationSource cacheOperationSource) このキャッシュアスペクトの CacheOperationSource を設定します。 |
void | setCacheOperationSources(CacheOperationSource... cacheOperationSources) キャッシュ属性の検索に使用される 1 つ以上のキャッシュ操作ソースを設定します。 |
void | setCacheResolver(CacheResolver cacheResolver) 操作に特定のキャッシュリゾルバーが設定されていない場合に、このキャッシュアスペクトが委譲するデフォルトの CacheResolver を設定します。 |
void | setKeyGenerator(KeyGenerator keyGenerator) 操作に特定のキージェネレーターが設定されていない場合、このキャッシュアスペクトが委譲するデフォルトの KeyGenerator を設定します。 |
doClear, doEvict, doGet, doPut, getErrorHandler, setErrorHandlercloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSEprotected final Log logger
public void configure(@Nullable SupplierSE<CacheErrorHandler> errorHandler, @Nullable SupplierSE<KeyGenerator> keyGenerator, @Nullable SupplierSE<CacheResolver> cacheResolver, @Nullable SupplierSE<CacheManager> cacheManager)
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources)
CompositeCacheOperationSource を使用して集約されます。public void setCacheOperationSource(@Nullable CacheOperationSource cacheOperationSource)
@Nullable public CacheOperationSource getCacheOperationSource()
public void setKeyGenerator(KeyGenerator keyGenerator)
KeyGenerator を設定します。 デフォルトは SimpleKeyGenerator です。
public KeyGenerator getKeyGenerator()
KeyGenerator を返します。public void setCacheResolver(@Nullable CacheResolver cacheResolver)
CacheResolver を設定します。デフォルトのリゾルバーは、名前とデフォルトのキャッシュマネージャーに対してキャッシュを解決します。
@Nullable public CacheResolver getCacheResolver()
CacheResolver を返します。public void setCacheManager(CacheManager cacheManager)
public void setBeanFactory(BeanFactory beanFactory)
BeanFactory を CacheManager およびその他のサービス検索用に設定します。BeanFactoryAware の setBeanFactory beanFactory - 所有 BeanFactory(非 null)。Bean は、ファクトリのメソッドをすぐに呼び出すことができます。BeanInitializationExceptionpublic void afterPropertiesSet()
InitializingBeanBeanFactoryAware、ApplicationContextAware などを満たした後、包含 BeanFactory によって呼び出されます。このメソッドにより、Bean インスタンスは、すべての Bean プロパティが設定されたときに、その全体的な構成の検証と最終的な初期化を実行できます。
InitializingBean の afterPropertiesSet public void afterSingletonsInstantiated()
SmartInitializingSingletonListableBeanFactory.getBeansOfType(java.lang.Class<T>) 呼び出しは、ブートストラップ中に偶発的な副作用を引き起こしません。 注意 : このコールバックは、BeanFactory ブートストラップ後にオンデマンドで遅延初期化されたシングルトン Bean ではトリガーされず、他の Bean スコープでもトリガーされません。意図されたブートストラップセマンティクスのみを使用する Bean には慎重に使用してください。
SmartInitializingSingleton の afterSingletonsInstantiated protected StringSE methodIdentification(MethodSE method, ClassSE<?> targetClass)
method - 興味のある方法 targetClass - メソッドが存在するクラス ClassUtils.getQualifiedMethodName(java.lang.reflect.Method)protected CollectionSE<? extends Cache> getCaches(CacheOperationInvocationContext<CacheOperation> context, CacheResolver cacheResolver)
protected CacheAspectSupport.CacheOperationContext getOperationContext(CacheOperation operation, MethodSE method, ObjectSE[] args, ObjectSE target, ClassSE<?> targetClass)
protected CacheAspectSupport.CacheOperationMetadata getCacheOperationMetadata(CacheOperation operation, MethodSE method, ClassSE<?> targetClass)
CacheAspectSupport.CacheOperationMetadata を返します。 操作に使用する CacheResolver および KeyGenerator を解決します。
operation - 操作 method - 操作が呼び出されるメソッド targetClass - ターゲット型 protected <T> T getBean(StringSE beanName, ClassSE<T> expectedType)
CacheOperation で名前によって参照されるサービスを解決するために使用されます。beanName - 操作で定義されている Bean の名前 expectedType - Bean の型 NoSuchBeanDefinitionException - そのような Bean が存在しない場合 CacheOperation.getKeyGenerator(), CacheOperation.getCacheManager(), CacheOperation.getCacheResolver()protected void clearMetadataCache()
@Nullable protected ObjectSE execute(CacheOperationInvoker invoker, ObjectSE target, MethodSE method, ObjectSE[] args)
@Nullable protected ObjectSE invokeOperation(CacheOperationInvoker invoker)
CacheOperationInvoker.ThrowableWrapper でラップされます。例外は処理または変更できますが、CacheOperationInvoker.ThrowableWrapper でもラップする必要があります。invoker - キャッシュされている操作を処理する呼び出し元 CacheOperationInvoker.invoke()