Skip to content

Commit d22cd0c

Browse files
mp911desnicoll
authored andcommitted
Align with breaking API changes in RedisCacheManager
See gh-9734
1 parent 5416eac commit d22cd0c

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.cache;
1818

19+
import java.util.LinkedHashSet;
1920
import java.util.List;
2021

2122
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -27,17 +28,19 @@
2728
import org.springframework.context.annotation.Conditional;
2829
import org.springframework.context.annotation.Configuration;
2930
import org.springframework.data.redis.cache.RedisCacheManager;
30-
import org.springframework.data.redis.core.RedisTemplate;
31+
import org.springframework.data.redis.cache.RedisCacheManager.RedisCacheManagerBuilder;
32+
import org.springframework.data.redis.connection.RedisConnectionFactory;
3133

3234
/**
3335
* Redis cache configuration.
3436
*
3537
* @author Stephane Nicoll
38+
* @author Mark Paluch
3639
* @since 1.3.0
3740
*/
3841
@Configuration
3942
@AutoConfigureAfter(RedisAutoConfiguration.class)
40-
@ConditionalOnBean(RedisTemplate.class)
43+
@ConditionalOnBean(RedisConnectionFactory.class)
4144
@ConditionalOnMissingBean(CacheManager.class)
4245
@Conditional(CacheCondition.class)
4346
class RedisCacheConfiguration {
@@ -53,14 +56,14 @@ class RedisCacheConfiguration {
5356
}
5457

5558
@Bean
56-
public RedisCacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate) {
57-
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
58-
cacheManager.setUsePrefix(true);
59+
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
60+
61+
RedisCacheManagerBuilder builder = RedisCacheManager.builder(redisConnectionFactory);
5962
List<String> cacheNames = this.cacheProperties.getCacheNames();
6063
if (!cacheNames.isEmpty()) {
61-
cacheManager.setCacheNames(cacheNames);
64+
builder.initialCacheNames(new LinkedHashSet<>(cacheNames));
6265
}
63-
return this.customizerInvoker.customize(cacheManager);
66+
return this.customizerInvoker.customize(builder.build());
6467
}
6568

6669
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
import org.springframework.core.io.ClassPathResource;
8080
import org.springframework.core.io.Resource;
8181
import org.springframework.data.redis.cache.RedisCacheManager;
82-
import org.springframework.data.redis.core.RedisTemplate;
82+
import org.springframework.data.redis.connection.RedisConnectionFactory;
8383

8484
import static org.assertj.core.api.Assertions.assertThat;
8585
import static org.mockito.BDDMockito.given;
@@ -92,6 +92,7 @@
9292
*
9393
* @author Stephane Nicoll
9494
* @author Eddú Meléndez
95+
* @author Mark Paluch
9596
*/
9697
@RunWith(ModifiedClassPathRunner.class)
9798
@ClassPathExclusions("hazelcast-client-*.jar")
@@ -282,8 +283,9 @@ public void redisCacheExplicit() {
282283
RedisCacheManager cacheManager = validateCacheManager(context,
283284
RedisCacheManager.class);
284285
assertThat(cacheManager.getCacheNames()).isEmpty();
285-
assertThat((Boolean) new DirectFieldAccessor(cacheManager)
286-
.getPropertyValue("usePrefix")).isTrue();
286+
org.springframework.data.redis.cache.RedisCacheConfiguration configuration = (org.springframework.data.redis.cache.RedisCacheConfiguration) new DirectFieldAccessor(
287+
cacheManager).getPropertyValue("defaultCacheConfig");
288+
assertThat(configuration.usePrefix()).isTrue();
287289
});
288290
}
289291

@@ -892,8 +894,8 @@ static class CouchbaseCacheAndCustomizersConfiguration {
892894
static class RedisCacheConfiguration {
893895

894896
@Bean
895-
public RedisTemplate<?, ?> redisTemplate() {
896-
return mock(RedisTemplate.class);
897+
public RedisConnectionFactory redisConnectionFactory() {
898+
return mock(RedisConnectionFactory.class);
897899
}
898900

899901
}

0 commit comments

Comments
 (0)