use of org.springframework.data.redis.cache.RedisCacheConfiguration in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method redisCacheWithRedisCacheManagerBuilderCustomizer.
@Test
void redisCacheWithRedisCacheManagerBuilderCustomizer() {
this.contextRunner.withUserConfiguration(RedisWithRedisCacheManagerBuilderCustomizerConfiguration.class).withPropertyValues("spring.cache.type=redis", "spring.cache.redis.time-to-live=15000").run((context) -> {
RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager.class);
RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofSeconds(10));
});
}
use of org.springframework.data.redis.cache.RedisCacheConfiguration in project thingsboard by thingsboard.
the class TBRedisCacheConfiguration method cacheManager.
/**
* Transaction aware RedisCacheManager.
* Enable RedisCaches to synchronize cache put/evict operations with ongoing Spring-managed transactions.
*/
@Bean
public CacheManager cacheManager(RedisConnectionFactory cf) {
DefaultFormattingConversionService redisConversionService = new DefaultFormattingConversionService();
RedisCacheConfiguration.registerDefaultConverters(redisConversionService);
registerDefaultConverters(redisConversionService);
RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig().withConversionService(redisConversionService);
return RedisCacheManager.builder(cf).cacheDefaults(configuration).transactionAware().build();
}
use of org.springframework.data.redis.cache.RedisCacheConfiguration in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method redisCacheWithRedisCacheConfiguration.
@Test
void redisCacheWithRedisCacheConfiguration() {
this.contextRunner.withUserConfiguration(RedisWithCacheConfigurationConfiguration.class).withPropertyValues("spring.cache.type=redis", "spring.cache.redis.time-to-live=15000", "spring.cache.redis.keyPrefix=foo").run((context) -> {
RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).isEmpty();
RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofSeconds(30));
assertThat(redisCacheConfiguration.getKeyPrefixFor("")).isEqualTo("bar::");
});
}
use of org.springframework.data.redis.cache.RedisCacheConfiguration in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method redisCacheExplicit.
@Test
void redisCacheExplicit() {
this.contextRunner.withUserConfiguration(RedisConfiguration.class).withPropertyValues("spring.cache.type=redis", "spring.cache.redis.time-to-live=15000", "spring.cache.redis.cacheNullValues=false", "spring.cache.redis.keyPrefix=prefix", "spring.cache.redis.useKeyPrefix=true").run((context) -> {
RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).isEmpty();
RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofSeconds(15));
assertThat(redisCacheConfiguration.getAllowCacheNullValues()).isFalse();
assertThat(redisCacheConfiguration.getKeyPrefixFor("MyCache")).isEqualTo("prefixMyCache::");
assertThat(redisCacheConfiguration.usePrefix()).isTrue();
});
}
use of org.springframework.data.redis.cache.RedisCacheConfiguration in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method redisCacheExplicitWithCaches.
@Test
void redisCacheExplicitWithCaches() {
this.contextRunner.withUserConfiguration(RedisConfiguration.class).withPropertyValues("spring.cache.type=redis", "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar").run((context) -> {
RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(cacheManager);
assertThat(redisCacheConfiguration.getTtl()).isEqualTo(java.time.Duration.ofMinutes(0));
assertThat(redisCacheConfiguration.getAllowCacheNullValues()).isTrue();
assertThat(redisCacheConfiguration.getKeyPrefixFor("test")).isEqualTo("test::");
assertThat(redisCacheConfiguration.usePrefix()).isTrue();
});
}
Aggregations