Skip to content

Improve RedisCacheManagerBuilder to expose applied RedisCacheConfiguration #2583

New issue

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

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

Already on GitHub? # 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
Expand Up @@ -41,6 +41,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Yanming Zhou
* @since 2.0
* @see RedisCacheConfiguration
* @see RedisCacheWriter
Expand Down Expand Up @@ -336,6 +337,15 @@ public RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCac
return this;
}

/**
* Returns applied {@link RedisCacheConfiguration}, allow customization base on it.
*
* @return applied {@link RedisCacheConfiguration}.
*/
public RedisCacheConfiguration cacheDefaults() {
return this.defaultCacheConfiguration;
}

/**
* Configure a {@link RedisCacheWriter}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.time.Duration;
import java.util.Collections;

import org.junit.jupiter.api.Test;
Expand All @@ -34,6 +35,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class RedisCacheManagerUnitTests {
Expand Down Expand Up @@ -188,4 +190,16 @@ void builderWontSetStatisticsCollectorByDefault() {

verify(cacheWriter, never()).withStatisticsCollector(any());
}

@Test // DATAREDIS-481
void customizeRedisCacheConfigurationBaseOnApplied() {

RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig().disableKeyPrefix();
RedisCacheManagerBuilder cmb = RedisCacheManager.builder().cacheDefaults(configuration);

cmb.cacheDefaults(cmb.cacheDefaults().entryTtl(Duration.ofSeconds(10)));

assertThat(cmb.cacheDefaults().usePrefix()).isFalse();
assertThat(cmb.cacheDefaults().getTtl()).isEqualTo(Duration.ofSeconds(10));
}
}