Skip to content

Align with breaking API changes in RedisCacheManager #9734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package org.springframework.boot.autoconfigure.cache;

import java.util.LinkedHashSet;
import java.util.List;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand All @@ -27,17 +28,19 @@
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.cache.RedisCacheManager.RedisCacheManagerBuilder;
import org.springframework.data.redis.connection.RedisConnectionFactory;

/**
* Redis cache configuration.
*
* @author Stephane Nicoll
* @author Mark Paluch
* @since 1.3.0
*/
@Configuration
@AutoConfigureAfter(RedisAutoConfiguration.class)
@ConditionalOnBean(RedisTemplate.class)
@ConditionalOnBean(RedisConnectionFactory.class)
@ConditionalOnMissingBean(CacheManager.class)
@Conditional(CacheCondition.class)
class RedisCacheConfiguration {
Expand All @@ -53,14 +56,14 @@ class RedisCacheConfiguration {
}

@Bean
public RedisCacheManager cacheManager(RedisTemplate<Object, Object> redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
cacheManager.setUsePrefix(true);
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {

RedisCacheManagerBuilder builder = RedisCacheManager.builder(redisConnectionFactory);
List<String> cacheNames = this.cacheProperties.getCacheNames();
if (!cacheNames.isEmpty()) {
cacheManager.setCacheNames(cacheNames);
builder.initialCacheNames(new LinkedHashSet<>(cacheNames));
}
return this.customizerInvoker.customize(cacheManager);
return this.customizerInvoker.customize(builder.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
Expand All @@ -92,6 +92,7 @@
*
* @author Stephane Nicoll
* @author Eddú Meléndez
* @author Mark Paluch
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("hazelcast-client-*.jar")
Expand Down Expand Up @@ -282,8 +283,9 @@ public void redisCacheExplicit() {
RedisCacheManager cacheManager = validateCacheManager(context,
RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).isEmpty();
assertThat((Boolean) new DirectFieldAccessor(cacheManager)
.getPropertyValue("usePrefix")).isTrue();
org.springframework.data.redis.cache.RedisCacheConfiguration configuration = (org.springframework.data.redis.cache.RedisCacheConfiguration) new DirectFieldAccessor(
cacheManager).getPropertyValue("defaultCacheConfig");
assertThat(configuration.usePrefix()).isTrue();
});
}

Expand Down Expand Up @@ -892,8 +894,8 @@ static class CouchbaseCacheAndCustomizersConfiguration {
static class RedisCacheConfiguration {

@Bean
public RedisTemplate<?, ?> redisTemplate() {
return mock(RedisTemplate.class);
public RedisConnectionFactory redisConnectionFactory() {
return mock(RedisConnectionFactory.class);
}

}
Expand Down