Search in sources :

Example 1 with CacheResolver

use of cn.taketoday.cache.interceptor.CacheResolver in project today-infrastructure by TAKETODAY.

the class JCacheJavaConfigTests method fullCachingConfig.

@Test
public void fullCachingConfig() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class);
    DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
    assertThat(cos.getKeyGenerator()).isSameAs(context.getBean(KeyGenerator.class));
    assertThat(cos.getCacheResolver()).isSameAs(context.getBean("cacheResolver", CacheResolver.class));
    assertThat(cos.getExceptionCacheResolver()).isSameAs(context.getBean("exceptionCacheResolver", CacheResolver.class));
    JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
    assertThat(interceptor.getErrorHandler()).isSameAs(context.getBean("errorHandler", CacheErrorHandler.class));
    context.close();
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) JCacheInterceptor(cn.taketoday.cache.jcache.interceptor.JCacheInterceptor) DefaultJCacheOperationSource(cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource) CacheErrorHandler(cn.taketoday.cache.interceptor.CacheErrorHandler) SimpleCacheErrorHandler(cn.taketoday.cache.interceptor.SimpleCacheErrorHandler) SimpleCacheResolver(cn.taketoday.cache.interceptor.SimpleCacheResolver) NamedCacheResolver(cn.taketoday.cache.interceptor.NamedCacheResolver) CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) SimpleKeyGenerator(cn.taketoday.cache.interceptor.SimpleKeyGenerator) KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator) SomeKeyGenerator(cn.taketoday.contextsupport.testfixture.cache.SomeKeyGenerator) Test(org.junit.jupiter.api.Test)

Example 2 with CacheResolver

use of cn.taketoday.cache.interceptor.CacheResolver in project today-infrastructure by TAKETODAY.

the class AnnotationJCacheOperationSource method createCacheRemoveOperation.

protected CacheRemoveOperation createCacheRemoveOperation(Method method, @Nullable CacheDefaults defaults, CacheRemove ann) {
    String cacheName = determineCacheName(method, defaults, ann.cacheName());
    CacheResolverFactory cacheResolverFactory = determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
    KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());
    CacheMethodDetails<CacheRemove> methodDetails = createMethodDetails(method, ann, cacheName);
    CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
    return new CacheRemoveOperation(methodDetails, cacheResolver, keyGenerator);
}
Also used : CacheRemove(javax.cache.annotation.CacheRemove) CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) CacheKeyGenerator(javax.cache.annotation.CacheKeyGenerator) KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator) CacheResolverFactory(javax.cache.annotation.CacheResolverFactory)

Example 3 with CacheResolver

use of cn.taketoday.cache.interceptor.CacheResolver in project today-infrastructure by TAKETODAY.

the class AnnotationJCacheOperationSource method createCacheResultOperation.

protected CacheResultOperation createCacheResultOperation(Method method, @Nullable CacheDefaults defaults, CacheResult ann) {
    String cacheName = determineCacheName(method, defaults, ann.cacheName());
    CacheResolverFactory cacheResolverFactory = determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
    KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());
    CacheMethodDetails<CacheResult> methodDetails = createMethodDetails(method, ann, cacheName);
    CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
    CacheResolver exceptionCacheResolver = null;
    final String exceptionCacheName = ann.exceptionCacheName();
    if (StringUtils.hasText(exceptionCacheName)) {
        exceptionCacheResolver = getExceptionCacheResolver(cacheResolverFactory, methodDetails);
    }
    return new CacheResultOperation(methodDetails, cacheResolver, keyGenerator, exceptionCacheResolver);
}
Also used : CacheResult(javax.cache.annotation.CacheResult) CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) CacheKeyGenerator(javax.cache.annotation.CacheKeyGenerator) KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator) CacheResolverFactory(javax.cache.annotation.CacheResolverFactory)

Example 4 with CacheResolver

use of cn.taketoday.cache.interceptor.CacheResolver in project today-infrastructure by TAKETODAY.

the class AnnotationJCacheOperationSource method createCachePutOperation.

protected CachePutOperation createCachePutOperation(Method method, @Nullable CacheDefaults defaults, CachePut ann) {
    String cacheName = determineCacheName(method, defaults, ann.cacheName());
    CacheResolverFactory cacheResolverFactory = determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
    KeyGenerator keyGenerator = determineKeyGenerator(defaults, ann.cacheKeyGenerator());
    CacheMethodDetails<CachePut> methodDetails = createMethodDetails(method, ann, cacheName);
    CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
    return new CachePutOperation(methodDetails, cacheResolver, keyGenerator);
}
Also used : CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) CacheKeyGenerator(javax.cache.annotation.CacheKeyGenerator) KeyGenerator(cn.taketoday.cache.interceptor.KeyGenerator) CachePut(javax.cache.annotation.CachePut) CacheResolverFactory(javax.cache.annotation.CacheResolverFactory)

Example 5 with CacheResolver

use of cn.taketoday.cache.interceptor.CacheResolver in project today-infrastructure by TAKETODAY.

the class AnnotationJCacheOperationSource method createCacheRemoveAllOperation.

protected CacheRemoveAllOperation createCacheRemoveAllOperation(Method method, @Nullable CacheDefaults defaults, CacheRemoveAll ann) {
    String cacheName = determineCacheName(method, defaults, ann.cacheName());
    CacheResolverFactory cacheResolverFactory = determineCacheResolverFactory(defaults, ann.cacheResolverFactory());
    CacheMethodDetails<CacheRemoveAll> methodDetails = createMethodDetails(method, ann, cacheName);
    CacheResolver cacheResolver = getCacheResolver(cacheResolverFactory, methodDetails);
    return new CacheRemoveAllOperation(methodDetails, cacheResolver);
}
Also used : CacheResolver(cn.taketoday.cache.interceptor.CacheResolver) CacheRemoveAll(javax.cache.annotation.CacheRemoveAll) CacheResolverFactory(javax.cache.annotation.CacheResolverFactory)

Aggregations

CacheResolver (cn.taketoday.cache.interceptor.CacheResolver)10 KeyGenerator (cn.taketoday.cache.interceptor.KeyGenerator)8 CacheResolverFactory (javax.cache.annotation.CacheResolverFactory)8 CacheKeyGenerator (javax.cache.annotation.CacheKeyGenerator)6 CacheErrorHandler (cn.taketoday.cache.interceptor.CacheErrorHandler)2 NamedCacheResolver (cn.taketoday.cache.interceptor.NamedCacheResolver)2 SimpleCacheErrorHandler (cn.taketoday.cache.interceptor.SimpleCacheErrorHandler)2 SimpleCacheResolver (cn.taketoday.cache.interceptor.SimpleCacheResolver)2 SimpleKeyGenerator (cn.taketoday.cache.interceptor.SimpleKeyGenerator)2 DefaultJCacheOperationSource (cn.taketoday.cache.jcache.interceptor.DefaultJCacheOperationSource)2 JCacheInterceptor (cn.taketoday.cache.jcache.interceptor.JCacheInterceptor)2 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)2 SomeKeyGenerator (cn.taketoday.contextsupport.testfixture.cache.SomeKeyGenerator)2 CachePut (javax.cache.annotation.CachePut)2 CacheRemove (javax.cache.annotation.CacheRemove)2 CacheRemoveAll (javax.cache.annotation.CacheRemoveAll)2 CacheResult (javax.cache.annotation.CacheResult)2 Test (org.junit.jupiter.api.Test)2