Search in sources :

Example 1 with JCacheInterceptor

use of org.springframework.cache.jcache.interceptor.JCacheInterceptor in project spring-framework by spring-projects.

the class ProxyJCacheConfiguration method cacheInterceptor.

@Bean(name = "jCacheInterceptor")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public JCacheInterceptor cacheInterceptor() {
    JCacheInterceptor interceptor = new JCacheInterceptor();
    interceptor.setCacheOperationSource(cacheOperationSource());
    if (this.errorHandler != null) {
        interceptor.setErrorHandler(this.errorHandler);
    }
    return interceptor;
}
Also used : JCacheInterceptor(org.springframework.cache.jcache.interceptor.JCacheInterceptor) Role(org.springframework.context.annotation.Role) Bean(org.springframework.context.annotation.Bean)

Example 2 with JCacheInterceptor

use of org.springframework.cache.jcache.interceptor.JCacheInterceptor in project spring-framework by spring-projects.

the class JCacheJavaConfigTests method fullCachingConfig.

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

Example 3 with JCacheInterceptor

use of org.springframework.cache.jcache.interceptor.JCacheInterceptor in project spring-framework by spring-projects.

the class JCacheNamespaceDrivenTests method testCacheErrorHandler.

@Test
public void testCacheErrorHandler() {
    JCacheInterceptor ci = ctx.getBean(JCacheInterceptor.class);
    assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
Also used : JCacheInterceptor(org.springframework.cache.jcache.interceptor.JCacheInterceptor) CacheErrorHandler(org.springframework.cache.interceptor.CacheErrorHandler) Test(org.junit.Test)

Example 4 with JCacheInterceptor

use of org.springframework.cache.jcache.interceptor.JCacheInterceptor in project spring-framework by spring-projects.

the class JCacheCustomInterceptorTests method onlyOneInterceptorIsAvailable.

@Test
public void onlyOneInterceptorIsAvailable() {
    Map<String, JCacheInterceptor> interceptors = ctx.getBeansOfType(JCacheInterceptor.class);
    assertEquals("Only one interceptor should be defined", 1, interceptors.size());
    JCacheInterceptor interceptor = interceptors.values().iterator().next();
    assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass());
}
Also used : JCacheInterceptor(org.springframework.cache.jcache.interceptor.JCacheInterceptor) Test(org.junit.Test)

Aggregations

JCacheInterceptor (org.springframework.cache.jcache.interceptor.JCacheInterceptor)4 Test (org.junit.Test)3 CacheErrorHandler (org.springframework.cache.interceptor.CacheErrorHandler)2 SomeKeyGenerator (org.springframework.cache.config.SomeKeyGenerator)1 CacheResolver (org.springframework.cache.interceptor.CacheResolver)1 KeyGenerator (org.springframework.cache.interceptor.KeyGenerator)1 NamedCacheResolver (org.springframework.cache.interceptor.NamedCacheResolver)1 SimpleCacheErrorHandler (org.springframework.cache.interceptor.SimpleCacheErrorHandler)1 SimpleCacheResolver (org.springframework.cache.interceptor.SimpleCacheResolver)1 SimpleKeyGenerator (org.springframework.cache.interceptor.SimpleKeyGenerator)1 DefaultJCacheOperationSource (org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 Role (org.springframework.context.annotation.Role)1