Java 类org.springframework.cache.annotation.CachingConfigurer 实例源码

项目:spring-cloud-aws    文件:ElastiCacheAutoConfigurationTest.java   
@Test
public void cacheManager_configuredMultipleCachesWithStack_configuresCacheManager() throws Exception {
    //Arrange
    HttpServer httpServer = MetaDataServer.setupHttpServer();
    HttpContext instanceIdHttpContext = httpServer.createContext("/latest/meta-data/instance-id", new MetaDataServer.HttpResponseWriterHandler("testInstanceId"));

    this.context = new AnnotationConfigApplicationContext();
    this.context.register(MockCacheConfigurationWithStackCaches.class);
    this.context.register(ElastiCacheAutoConfiguration.class);

    //Act
    this.context.refresh();

    //Assert
    CacheManager cacheManager = this.context.getBean(CachingConfigurer.class).cacheManager();
    assertTrue(cacheManager.getCacheNames().contains("sampleCacheOneLogical"));
    assertTrue(cacheManager.getCacheNames().contains("sampleCacheTwoLogical"));
    assertEquals(2, cacheManager.getCacheNames().size());

    httpServer.removeContext(instanceIdHttpContext);
}
项目:spring-cloud-aws    文件:ElastiCacheAutoConfigurationTest.java   
@Test
public void cacheManager_configuredNoCachesWithNoStack_configuresNoCacheManager() throws Exception {
    //Arrange
    HttpServer httpServer = MetaDataServer.setupHttpServer();
    HttpContext instanceIdHttpContext = httpServer.createContext("/latest/meta-data/instance-id", new MetaDataServer.HttpResponseWriterHandler("testInstanceId"));

    this.context = new AnnotationConfigApplicationContext();
    this.context.register(ElastiCacheAutoConfiguration.class);

    //Act
    this.context.refresh();

    //Assert
    CacheManager cacheManager = this.context.getBean(CachingConfigurer.class).cacheManager();
    assertEquals(0, cacheManager.getCacheNames().size());

    httpServer.removeContext(instanceIdHttpContext);
}
项目:spring-cloud-aws    文件:ElastiCacheCachingConfigurationTest.java   
@Test
public void enableElasticache_configuredWithExplicitCluster_configuresExplicitlyConfiguredCaches() throws Exception {
    //Arrange

    //Act
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithExplicitStackConfiguration.class);

    //Assert
    CacheManager cacheManager = this.context.getBean(CachingConfigurer.class).cacheManager();
    assertEquals(2, cacheManager.getCacheNames().size());
    Cache firstCache = cacheManager.getCache("firstCache");
    assertNotNull(firstCache.getName());
    assertEquals(0, getExpirationFromCache(firstCache));

    Cache secondCache = cacheManager.getCache("secondCache");
    assertNotNull(secondCache.getName());
    assertEquals(0, getExpirationFromCache(secondCache));
}
项目:spring-cloud-aws    文件:ElastiCacheCachingConfigurationTest.java   
@Test
public void enableElasticache_configuredWithExplicitClusterAndExpiration_configuresExplicitlyConfiguredCachesWithCustomExpirationTimes() throws Exception {
    //Arrange

    //Act
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithExplicitStackConfigurationAndExpiryTime.class);

    //Assert
    CacheManager cacheManager = this.context.getBean(CachingConfigurer.class).cacheManager();
    assertEquals(2, cacheManager.getCacheNames().size());
    Cache firstCache = cacheManager.getCache("firstCache");
    assertNotNull(firstCache.getName());
    assertEquals(23, getExpirationFromCache(firstCache));

    Cache secondCache = cacheManager.getCache("secondCache");
    assertNotNull(secondCache.getName());
    assertEquals(42, getExpirationFromCache(secondCache));
}
项目:spring-cloud-aws    文件:ElastiCacheCachingConfigurationTest.java   
@Test
public void enableElasticache_configuredWithExplicitClusterAndExpiration_configuresExplicitlyConfiguredCachesWithMixedExpirationTimes() throws Exception {
    //Arrange

    //Act
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithExplicitStackConfigurationAndMixedExpiryTime.class);

    //Assert
    CacheManager cacheManager = this.context.getBean(CachingConfigurer.class).cacheManager();
    assertEquals(2, cacheManager.getCacheNames().size());
    Cache firstCache = cacheManager.getCache("firstCache");
    assertNotNull(firstCache.getName());
    assertEquals(12, getExpirationFromCache(firstCache));

    Cache secondCache = cacheManager.getCache("secondCache");
    assertNotNull(secondCache.getName());
    assertEquals(42, getExpirationFromCache(secondCache));
}
项目:spring-cloud-aws    文件:ElastiCacheCachingConfigurationTest.java   
@Test
public void enableElasticache_configuredWithoutExplicitCluster_configuresImplicitlyConfiguredCaches() throws Exception {
    //Arrange

    //Act
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithNoExplicitStackConfiguration.class);

    //Assert
    CacheManager cacheManager = this.context.getBean(CachingConfigurer.class).cacheManager();
    assertEquals(2, cacheManager.getCacheNames().size());
    Cache firstCache = cacheManager.getCache("sampleCacheOneLogical");
    assertNotNull(firstCache.getName());
    assertEquals(0, getExpirationFromCache(firstCache));

    Cache secondCache = cacheManager.getCache("sampleCacheTwoLogical");
    assertNotNull(secondCache.getName());
    assertEquals(0, getExpirationFromCache(secondCache));
}
项目:spring-cloud-aws    文件:ElastiCacheCachingConfigurationTest.java   
@Test
public void enableElasticache_configuredWithoutExplicitClusterButDefaultExpiryTime_configuresImplicitlyConfiguredCachesWithDefaultExpiryTimeOnAllCaches() throws Exception {
    //Arrange

    //Act
    this.context = new AnnotationConfigApplicationContext(ApplicationConfigurationWithNoExplicitStackConfigurationAndDefaultExpiration.class);

    //Assert
    CacheManager cacheManager = this.context.getBean(CachingConfigurer.class).cacheManager();
    assertEquals(2, cacheManager.getCacheNames().size());
    Cache firstCache = cacheManager.getCache("sampleCacheOneLogical");
    assertNotNull(firstCache.getName());
    assertEquals(23, getExpirationFromCache(firstCache));

    Cache secondCache = cacheManager.getCache("sampleCacheTwoLogical");
    assertNotNull(secondCache.getName());
    assertEquals(23, getExpirationFromCache(secondCache));
}
项目:spring4-understanding    文件:AbstractJCacheConfiguration.java   
@Override
protected void useCachingConfigurer(CachingConfigurer config) {
    super.useCachingConfigurer(config);
    if (config instanceof JCacheConfigurer) {
        this.exceptionCacheResolver = ((JCacheConfigurer) config).exceptionCacheResolver();
    }
}
项目:spring-cloud-aws    文件:ElastiCacheCachingConfiguration.java   
@Bean
public CachingConfigurer cachingConfigurer(AmazonElastiCache amazonElastiCache, ResourceIdResolver resourceIdResolver,
                                           List<CacheFactory> cacheFactories) {
    if (this.annotationAttributes != null && this.annotationAttributes.getAnnotationArray("value").length > 0) {
        return new ElastiCacheCacheConfigurer(amazonElastiCache, resourceIdResolver,
                getCacheNamesFromCacheClusterConfigs(this.annotationAttributes.getAnnotationArray("value")), cacheFactories);
    } else {
        return new ElastiCacheCacheConfigurer(amazonElastiCache, resourceIdResolver,
                getConfiguredCachesInStack(), cacheFactories);
    }
}
项目:onetwo    文件:SpringCacheConfiguration.java   
@Bean
public CachingConfigurer simpleCachingConfigurer(){
    return new SimpleCachingConfigurer();
}