org.springframework.cache.interceptor.CacheInterceptor Java Examples
The following examples show how to use
org.springframework.cache.interceptor.CacheInterceptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProxyCachingConfiguration.java From lams with GNU General Public License v2.0 | 6 votes |
@Bean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public CacheInterceptor cacheInterceptor() { CacheInterceptor interceptor = new CacheInterceptor(); interceptor.setCacheOperationSources(cacheOperationSource()); if (this.cacheResolver != null) { interceptor.setCacheResolver(this.cacheResolver); } else if (this.cacheManager != null) { interceptor.setCacheManager(this.cacheManager); } if (this.keyGenerator != null) { interceptor.setKeyGenerator(this.keyGenerator); } if (this.errorHandler != null) { interceptor.setErrorHandler(this.errorHandler); } return interceptor; }
Example #2
Source File: ProxyCachingConfiguration.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Bean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public CacheInterceptor cacheInterceptor() { CacheInterceptor interceptor = new CacheInterceptor(); interceptor.setCacheOperationSources(cacheOperationSource()); if (this.cacheResolver != null) { interceptor.setCacheResolver(this.cacheResolver); } else if (this.cacheManager != null) { interceptor.setCacheManager(this.cacheManager); } if (this.keyGenerator != null) { interceptor.setKeyGenerator(this.keyGenerator); } if (this.errorHandler != null) { interceptor.setErrorHandler(this.errorHandler); } return interceptor; }
Example #3
Source File: AnnotationNamespaceDrivenTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void cacheResolver() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
Example #4
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From spring-analysis-note with MIT License | 5 votes |
private static void registerCacheAdvisor(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) { Object eleSource = parserContext.extractSource(element); // Create the CacheOperationSource definition. RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the CacheInterceptor definition. RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); parseCacheResolution(element, interceptorDef, false); parseErrorHandler(element, interceptorDef); CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef); interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the CacheAdvisor definition. RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)); parserContext.registerComponent(compositeDef); } }
Example #5
Source File: AnnotationNamespaceDrivenTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
Example #6
Source File: CustomInterceptorTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void onlyOneInterceptorIsAvailable() { Map<String, CacheInterceptor> interceptors = this.ctx.getBeansOfType(CacheInterceptor.class); assertEquals("Only one interceptor should be defined", 1, interceptors.size()); CacheInterceptor interceptor = interceptors.values().iterator().next(); assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass()); }
Example #7
Source File: EnableCachingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void emptyConfigSupport() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertNotNull(ci.getCacheResolver()); assertEquals(SimpleCacheResolver.class, ci.getCacheResolver().getClass()); assertSame(context.getBean(CacheManager.class), ((SimpleCacheResolver)ci.getCacheResolver()).getCacheManager()); context.close(); }
Example #8
Source File: EnableCachingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); assertSame(context.getBean("keyGenerator"), ci.getKeyGenerator()); context.close(); }
Example #9
Source File: ProxyCachingConfigurationInitializer.java From spring-init with Apache License 2.0 | 5 votes |
@Override public void initialize(GenericApplicationContext context) { context.registerBean(ProxyCachingConfiguration.class, () -> new ProxyCachingConfiguration()); context.registerBean(CacheInterceptor.class, () -> context.getBean(ProxyCachingConfiguration.class) .cacheInterceptor(context.getBean(CacheOperationSource.class))); context.registerBean(CacheOperationSource.class, () -> context.getBean(ProxyCachingConfiguration.class).cacheOperationSource()); context.registerBean(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, BeanFactoryCacheOperationSourceAdvisor.class, () -> context.getBean(ProxyCachingConfiguration.class).cacheAdvisor( context.getBean(CacheOperationSource.class), context.getBean(CacheInterceptor.class))); }
Example #10
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static void registerCacheAdvisor(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) { Object eleSource = parserContext.extractSource(element); // Create the CacheOperationSource definition. RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the CacheInterceptor definition. RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); parseCacheResolution(element, interceptorDef, false); parseErrorHandler(element, interceptorDef); CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef); interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the CacheAdvisor definition. RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)); parserContext.registerComponent(compositeDef); } }
Example #11
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
private static void registerCacheAdvisor(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) { Object eleSource = parserContext.extractSource(element); // Create the CacheOperationSource definition. RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the CacheInterceptor definition. RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); parseCacheResolution(element, interceptorDef, false); parseErrorHandler(element, interceptorDef); CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef); interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the CacheAdvisor definition. RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)); parserContext.registerComponent(compositeDef); } }
Example #12
Source File: AnnotationNamespaceDrivenTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void cacheResolver() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
Example #13
Source File: AnnotationNamespaceDrivenTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
Example #14
Source File: CustomInterceptorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void onlyOneInterceptorIsAvailable() { Map<String, CacheInterceptor> interceptors = ctx.getBeansOfType(CacheInterceptor.class); assertEquals("Only one interceptor should be defined", 1, interceptors.size()); CacheInterceptor interceptor = interceptors.values().iterator().next(); assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass()); }
Example #15
Source File: EnableCachingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void emptyConfigSupport() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertNotNull(ci.getCacheResolver()); assertEquals(SimpleCacheResolver.class, ci.getCacheResolver().getClass()); assertSame(context.getBean(CacheManager.class), ((SimpleCacheResolver)ci.getCacheResolver()).getCacheManager()); context.close(); }
Example #16
Source File: EnableCachingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); assertSame(context.getBean("keyGenerator"), ci.getKeyGenerator()); context.close(); }
Example #17
Source File: SpringRabbitTracingTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void decorateSimpleRabbitListenerContainerFactory_appends_as_first_when_absent() { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setAdviceChain(new CacheInterceptor()); // the order of advices is important for the downstream interceptor to see the tracing context assertThat(rabbitTracing.decorateSimpleRabbitListenerContainerFactory(factory).getAdviceChain()) .hasSize(2) .matches(adviceArray -> adviceArray[0] instanceof TracingRabbitListenerAdvice); }
Example #18
Source File: CustomInterceptorTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void onlyOneInterceptorIsAvailable() { Map<String, CacheInterceptor> interceptors = this.ctx.getBeansOfType(CacheInterceptor.class); assertEquals("Only one interceptor should be defined", 1, interceptors.size()); CacheInterceptor interceptor = interceptors.values().iterator().next(); assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass()); }
Example #19
Source File: ProxyCachingConfiguration.java From spring-analysis-note with MIT License | 5 votes |
@Bean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public CacheInterceptor cacheInterceptor() { CacheInterceptor interceptor = new CacheInterceptor(); interceptor.configure(this.errorHandler, this.keyGenerator, this.cacheResolver, this.cacheManager); interceptor.setCacheOperationSource(cacheOperationSource()); return interceptor; }
Example #20
Source File: AnnotationNamespaceDrivenTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void cacheResolver() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
Example #21
Source File: AnnotationNamespaceDrivenTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new GenericXmlApplicationContext( "/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml"); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); context.close(); }
Example #22
Source File: EnableCachingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void emptyConfigSupport() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertNotNull(ci.getCacheResolver()); assertEquals(SimpleCacheResolver.class, ci.getCacheResolver().getClass()); assertSame(context.getBean(CacheManager.class), ((SimpleCacheResolver)ci.getCacheResolver()).getCacheManager()); context.close(); }
Example #23
Source File: EnableCachingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void bothSetOnlyResolverIsUsed() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class); CacheInterceptor ci = context.getBean(CacheInterceptor.class); assertSame(context.getBean("cacheResolver"), ci.getCacheResolver()); assertSame(context.getBean("keyGenerator"), ci.getKeyGenerator()); context.close(); }
Example #24
Source File: ProxyCachingConfiguration.java From java-technology-stack with MIT License | 5 votes |
@Bean @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public CacheInterceptor cacheInterceptor() { CacheInterceptor interceptor = new CacheInterceptor(); interceptor.configure(this.errorHandler, this.keyGenerator, this.cacheResolver, this.cacheManager); interceptor.setCacheOperationSource(cacheOperationSource()); return interceptor; }
Example #25
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
private static void registerCacheAdvisor(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) { Object eleSource = parserContext.extractSource(element); // Create the CacheOperationSource definition. RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource"); sourceDef.setSource(eleSource); sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); // Create the CacheInterceptor definition. RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class); interceptorDef.setSource(eleSource); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); parseCacheResolution(element, interceptorDef, false); parseErrorHandler(element, interceptorDef); CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef); interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName)); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); // Create the CacheAdvisor definition. RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class); advisorDef.setSource(eleSource); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); } parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName)); compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)); parserContext.registerComponent(compositeDef); } }
Example #26
Source File: AnnotationNamespaceDrivenTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testCacheErrorHandler() { CacheInterceptor ci = this.ctx.getBean( "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler()); }
Example #27
Source File: CacheAdviceParser.java From java-technology-stack with MIT License | 4 votes |
@Override protected Class<?> getBeanClass(Element element) { return CacheInterceptor.class; }
Example #28
Source File: CacheAdviceParser.java From spring-analysis-note with MIT License | 4 votes |
@Override protected Class<?> getBeanClass(Element element) { return CacheInterceptor.class; }
Example #29
Source File: AnnotationNamespaceDrivenTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testKeyStrategy() { CacheInterceptor ci = this.ctx.getBean( "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); assertSame(this.ctx.getBean("keyGenerator"), ci.getKeyGenerator()); }
Example #30
Source File: EnableCachingTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void testCacheErrorHandler() { CacheInterceptor ci = ctx.getBean(CacheInterceptor.class); assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler()); }